I've learned that a simple way of creating MenuItems is to create a method for it in which you add listeners to them and set their properties. Even back then, I couldn't find out a way to later on set any property of them. Now I'm trying to create TextFields just the same way, and I've almost found a way to set things after I've created them, but still, I fail.
Here are the methods I'd created so far
for creating the textfields, and for getting to them:
does nothing. In fact setBackground does nothing as well.. setEnabled(fals e) gets to somehow freeze the whole application. It's like by calling getByName method I'd get the whole JFrame or something - which is not the case.
The question is, what do i do wrong?
Any clue would be much appreciated!
Thank you:)
Here are the methods I'd created so far
Code:
private TextField createTextField(String text, String name, int cols)
{
TextField nextTextField = new TextField(text, cols);
nextTextField.setName(name); //for me to have something simple to refer to this object later on
return nextTextField;
}
Code:
private Component getByName(String componentName, Container cont)
{
for(Component c : cont.getComponents())
{
System.out.println(c.getName()); //to be able to see where the search is going
if(c.getName() == componentName)
{
return this.getComponentAt(c.getLocation());
}
}
return null;
}
Code:
getByName("Nickname", leftPanel).setForeground(Color.orange);
The question is, what do i do wrong?
Any clue would be much appreciated!
Thank you:)
Comment