Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField text reload problem  RSS feed

 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have a JTextField when I first load it and input some text in it, it works fine. Then if I load it again, the previous text I entered remains there when I put my mouse over it.

I want the text not to show like if the field is blank all the time. I tried using JTextField's setText() method before adding it to the JPanel. But that didn't work. If I check if the text is present using getText() method, I get null. So that didn't work.

Any ideas? Thanks.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "load" I presume you mean adding it to some panel.
Usually you need to add it only once. Whenever you want to change the text, you can easily do it by calling the setText() method.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "load" I mean the text inside the text field not the component per se. See screenshot. The top shows the first time I open the dialog box and type "999" into it. Then I click cancel or book button. The bottom shows the identical dialog but the "999" is already there. I want the text to disappear so that my mouse cursor is at the beginning of the text field rather than x positions inward.

Hope now you get my idea.
Filename: screenshot.bmp
Description: screenshot
File size: 265 Kbytes
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the text to dissapear, simply call setText("");
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or setText(null);
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!