Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Swing: repaint and setVisible

Thu Oct 23, 2008 12:39 am

I am developing a simple program to add 2 numbers. It
contains 2 TextFields and 1 Button. When clicked on button, button handler
will add 2 numbers in text fields and puts it in label, add it to the panel.
(All components are panel, and panel is added to the frame.)

The problem is that after adding the label to the panel, I am calling
repaint method on panel, or frame not updating the GUI. But, when I resize
the window with mouse, it updating. If hiding the panel, or frame by using
setVisible and making it visible again updating the GUI.

But, I didn't understand why repaint is not updating the GUI?



Re: Swing: repaint and setVisible

Thu Oct 23, 2008 12:40 am

It's been a while since I worked in Swing, but this is what I remember:

You can't call repaint () from the code handling your request. This is
the Swing dispatch thread. Instead, use invokeAndWait or invokeLater (I
would advise invokeLater, because it runs the repaint process
asynchronously). See Java's JavaDoc of the SwingUtilities class:
http://java.sun.com/j2se/1.5.0/docs/api ... ities.html

Also check out the Swing tutorial:
http://java.sun.com/docs/books/tutorial ... index.html

Post a reply
  Related Posts  to : Swing: repaint and setVisible
 What is Swing?!!     -  
 JUnit Testing of GUIs in Swing     -  
 How to create a log in form using javax.swing     -  
 JLabel Class Example Swing Package     -  
 database contents display in table format in swing     -  
 a moving graph sortof widget build using Swing     -  
 old NASA style counter built from Swing components     -  
 an ammeter ( round gauge ) sortof widget built using Swing     -