• Post Reply Bookmark Topic Watch Topic
  • New Topic

repaint problem in swing  RSS feed

 
Jitender Yadav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We are developing an application using swing controls (thick client). The application has a menu structure and many times you click some buttons here and there on the page that takes you to the next page. We have followed a MDI structure where a JDesktopPane is added and we are adding our JPanel/JInternalFrame and other controls to the JDesktopPane.
Now the problem is, when i start the application the structure that holds the MDI comes properly, on clicking one of the menus i should am adding a panel to the desktoppane. Though its added but the page is not repainted. Only if i resize the frame, i see the newly added panel. This problem is coming consistently across for all the pages.
Is it because i have defined BorderLayout for the DesktopPane.
Thanks in adv.
Regards,
Jeetu
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try calling invalidate(), validate(), and/or repaint() right after you add your component. Without seeing the code it could be a problem with either components being added without being layed out...
 
Jitender Yadav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following method is invoked in the actionPerformed of a menuItem. This is suppose to add ClientRootDetails to the desktopPane. ClientrootDetails is another swing page that extends JInternalFrame. It holds a public method GetJContentPane() which is added here.

Please let me know if you need any further information. I have included the method that creates an instance of JDesktopPane in the previous commnnication.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
calling pack() on the frame after changing the content (adding/removing components from the content pane) will re-render the frame. setSize is of course unnecessary in that case.
if you need something like a wizard in swing: that is: the user clicks through a series of forms/panels/whatever, you normally would use a CardLayout. This means to instantiate all panels up front, and the cardlayout controlls the changing of the view. this works far better than calling repaint or validate (the latter can have different effects on different java platforms from what I experienced). as the user notices slow performance more during the actual runtime of the program than at startup, it is better to load all components that are most likely needed later on, at startup (saves you from if-clauses as well).
with CardLayout it's easy to implement a previous/next navigation and states. in the swing tutorial there is a good explanation on how to use it. actually, it's very easy.
chantal
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!