How can I remove a JScrollPane
from a JFrame
?
Here is an example of what I tried, but it isn't working:
Container gContentPane = frame.getContentPane();
JScrollPane scroll = new JScrollPane(gContentPane);
frame.setContentPane( scroll );
frame.revalidate();
frame.repaint();
if (scroll != null){
frame.getContentPane().remove(scroll);
frame.revalidate();
frame.repaint();
}
The JScrollPane
is still there even after frame.getContentPane().remove(scroll);
. What do I need to change to remove it?
If you want to remove something in Swing, firstly it has to be added. You did not add the scroll pane nowhere so I would suggest just changing the content pane to the previous one.
Container gContentPane = frame.getContentPane();
JScrollPane scroll = new JScrollPane(gContentPane);
frame.setContentPane( scroll );
frame.revalidate();
frame.repaint();
if (scroll != null) {
frame.setContentPane(gContentPane);
frame.revalidate();
frame.repaint();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.