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

How to prevent AWT component flicker?  RSS feed

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My main Frame has two Panels added to it. Each of the Panels contain various components and custom components. Question is: how can I make it so the two Panels are added to the Frame (or are made visible) only after each of the Panels' components are fully rendered. I just need new screens to be shown cleanly, without flickering! (Am using JDK1.1) Thanks in advance, James
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how can I make it so the two Panels are added to the Frame (or are made visible) only after each of the Panels' components are fully rendered.


Add them to the panel before you call setVisible(true) on the Frame...

If this problem is related to animation on components, though - you may want to google 'AWT "double buffering"'.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate,

Thanks for the reply. I can't call setVisible(false) on the Frame, cos it must be showing all the time.

Instead, I have tried this:
1. doing panel.setVisible(false)
2. adding the components, etc. to panel
3. doing panel.setVisible(true)
4. adding panel to the Frame

...but panel does not show on the Frame (despite panel.isVisible() returning true). Any idea what the problem is?

Thank you,
James
 
Campbell Ritchie
Sheriff
Posts: 55334
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either:-
  • Don't call setVisible(true) until after you have added every component, OR,
  • put a validate(); statement as the last line of the constructor when you have added all components.
  • CR
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!