Setting the text of a TextField
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ralph_Nair
Posted On:   Wednesday, November 5, 2008 02:24 PM

			
hello friends,
this may be a very stupid doubt but this thing is going over my head.

I want to set the text of the textfield t1 to null, on the click of the button b1, for which i wrote the following code:

if(ae.getSource() == b1)
if(b1.getText().equals("ADD"))
{

t1.setText("");
b1.setText("SAVE");
}

sadly, the text of the button changes to save, but the text of the textfield remains the same.

Please help me if possible!!

thanks!!

Re: Setting the text of a TextField

Posted By:   Robert_Lybarger  
Posted On:   Wednesday, November 5, 2008 07:31 PM

the setText("string here") method is the correct way to put something into a text field object. If it isn't working, then you have something [else] going wrong.

Unrelated design criticism, but don't change the label of a button, as it can cause layout or other rendering issues, some of which depend on the layout manager being used. Especially when the label changes the meaning of the button and thereby changes the event processing that occurs downstream. Instead, create two buttons and put them both into a panel with a CardLayout, and then show the appropriate card based on the events you are handling. (And keep the event handling separate.) Trust me.

About | Sitemap | Contact