Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete part of JPanel

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

How I can remove the EAST side of a JPanel that has BorderLayout? The EAST side, contains another JPanel.

Thank you
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the East side is a JPanel, and you want to remove it, you could just remove the JPanel from the JFrame...
Here is something I found from another site... :
"the easiest way to remove a component (panel) from a container (frame) is to keep a reference to it, and then call Container.remove(Component) ie:
i haven't tested this code but it should work.
"
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't call Thread.sleep(...) on the EDT.
 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really didn''t understand the example code, sorry :S
 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just want to remove the very first (default) JPanel that appeared on EAST side of the frame. Achieved to update it, but seems that update version hidden behind default JPanel, can't remove it.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no
very first (default) JPanel that appeared on EAST side of the frame


If you didn't add a Component with constraint of BorderLayout.EAST, there's nothing there. And if you did,then you need to retain a reference to allow you toremove it.

Whenever adding/removing components to/from an already visible container, you need to call revalidate() and repaint().

To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic