Eclipse wont create JLabels [message #1405403] |
Thu, 07 August 2014 09:22 |
Vangelis Michos Messages: 6 Registered: July 2014 |
Junior Member |
|
|
I'm having this issue with Eclipse. I have an app window that has 3 JTextFields. I want everytime to check if the field has an acceptable value and if not, create under it a JLabel in red that will indicate the error. Because I used absolute layout, I needed to know the coordinates of the JLabel for the setBounds() method. So what i did was create the Jlabels from the Design Tab, then click on them and then I went to their code. With the design manager, the red JLabel would be visible right from the start and that is not what should happen. So i copied the code which created the JLabel via the Design Tab, and placed it inside a MouseEvent so everytime the user will hit the button to make something in my program, I will check the values and if something is wrong, i create the JLabel with the same code inside the " if clause" which checks for the input values. The thing is that my JLabel wont create it self and thats the issue with all of my "if" clauses inside my program.
For example, this JLabel never gets created,no matter what value I give:
String sql_year = year.getText();
// year is my JTextField()
if((sql_year.length()>5)||(sql_year.length()<4))
{
JLabel digit = new JLabel("Error. Year is a 4-5 digit number!!");
digit.setForeground(Color.RED);
digit.setBounds(221, 126, 222, 38);
frame.getContentPane().add(digit);
digit.setVisible(true);
year.setText("");
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.08446 seconds