Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to alter label on UI

 
Umesh Vajpai
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

can someone get me some idea on to alter the label on the UI between a call. I was trying to set in this manner-
label4.setText("Status in progress...");
rm.run(path,binding);
label4.setText("Completed");

Thanks in Advance.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
label4.setText("Status in progress...");
(separate thread, not the EDT) --> rm.run(path,binding);
label4.setText("Completed"); (you do this from the separate thread (at the end of it,
via SwingUtilities.invokeLater(), to get it back on the EDT))
 
Sagar Dabas
Ranch Hand
Posts: 47
C++ Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. remove the label from its container....
2. then repaint() container....

3. label4.setText("Completed");
4. add the label again
5. revalidate() container.


 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really shouldn't need to remove and re-add the label. Just repainting ought to be enough (possibly repainting the container as well) - though Michael's solution is better.
 
Campbell Ritchie
Marshal
Posts: 52621
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUIs forum.
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar Dabas wrote:1. remove the label from its container....
2. then repaint() container....

3. label4.setText("Completed");
4. add the label again
5. revalidate() container.


Misguided advice and totally wrong.

Matthew Brown wrote:Just repainting ought to be enough (possibly repainting the container as well)

JLabel#setText(...) calls revalidate() and repaint() already.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!