Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why repaint is not updating GUI?  RSS feed

 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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...
 
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
Call panel.revalidate() along with panel.repaint()
 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you every one.
 
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
Ulf,

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