• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

why repaint is not updating GUI?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am newbie in Swing. 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? Please give me some hints...
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Call panel.revalidate() along with panel.repaint()
 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Maneesh Godbole. panel.revalidate() alone working. But, I am curious to know why repaint is not updating the GUI?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Creating the layout from scratch is an overhead that the creators of AWT probably thought unnecessary during painting, given that painting occurs much more frequently than changes to the UI. Considering that most GUIs do not change after they are created, that seems like a good decision.
 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you every one.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf,

My experience is that sometimes, only revalidate() works where as sometimes repaint() is required too? Any idea why this happens?
 
reply
    Bookmark Topic Watch Topic
  • New Topic