• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

repaint problem in swing

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic