• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't Remove Component from JPanel  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, I have a JPanel, in its constructor a JScrollPane is added.
And thats fine, it shows up fine.
There is also a JButton on the panel, which I want to be able to remove the JScrollPane, but it doesn't seem to work.

Here is the code I have for when the button is pressed...


But after pressing, the JScrollPane is still present, what am I doing wrong ?

Thanks for any help
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> this.validate();

try
this.revalidate();//for swing components
this.repaint();//sometimes required, sometimes not, safest to include
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought about doing that too, but doesn't repaint just invoke the paintComponent(Graphics g) method?

Anyway, I've changed it so that I have 2 components, when I press button it makes one visible, the other not visible, and that works fine.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!