Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing HELP!

 
Janine Williams
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a problem, I'm working on an application that has several text labels, the way that I want the labels to be coded is so that if the text area for the corresponding label NEEDS to be filled it will appear red, and once the required information has been filled in then the label will change to black.
Please help!
Janine
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not exactly what you are trying to do but I think I have an idea. I'm assuming that the user is going to click a button when he is done? If this is the case why don't you set up two arrays, on of labels(JLabels) and one of textFields(JTextFields). The indeices should correspond to each other. What I mean is if you have a label that says: "Name" and a textField for the user to fill in then label[0] should be the "Name" label and textField[0] should be the textField corresponding to it. Then just go with a for loop and check to make sure all textFields are filled in:
for( int i = 0; i < size; i++)
{
if( ( textField[i].getText() ).equals(null) ) //or textField[i].getText() == null;
{
label[i].setForeground(Color.red);
label[i].setText("Please Fill this in");
}
}
If you want to check for specific information in each textField than this will be a little harder.
I didn't have time to compile this for errors but I think it'll work
Hope this helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic