• Post Reply Bookmark Topic Watch Topic
  • New Topic

When does a peer get set?  RSS feed

 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a problem with JPanel. When I first create a JFrame and add a JPanel to it the the JPanel has a valid internal peer object. However, when I remove the JPanel and add a new one, the new one does not get its peer value set. Consequently isDisplayable() returns false and createImage() returns null. Does anyone know why it is when I create a new JPanel and add it to the JFrame it does not get its peer set?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are removing and adding the new JPanel after the application is running, you need to tell the underlying content pane to repaint itself so that you get the updated content.

Typically, calling the validate() method on the container who's children have been modified will take care of this.
 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply. I'm sorry I should have been more specific in my original posting. I have tried using validate() and validateTree() as well. But the result is the same. The JPanel looses the peer. When I call createImage() on the JPanel I get back null because the peer is null.

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "super" in your case here? What about getContentPane().validate() ?
[ December 25, 2005: Message edited by: Gregg Bolinger ]
 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's an interesting point. I figured calling validate() on the JFrame itself would go and validate everything in it. I changed the code to validate the content pane but unfortunately it had no effect. When I run the createImage(int, int) after I put a new PlotPanel object in the JFrame the new PlotPanel object's internal getPeer() object is null. Consequently createImage(int,int) returns null and I get NullPointerExceptions in my code. I tried calling validate() on everything I have in the JFrame but getPeer() is still null. This is so strange. The JFrame redraws and displays correctly after I put in a new PlotPanel and it does this with a null getPeer() object.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!