Is there any way of removing the Component
added to the CENTER
of a JPanel
with a BorderLayout
, without having to reference the Component
itself?
views:
529answers:
1
+3
A:
Something like this?
BorderLayout layout = panel.getLayout();
panel.remove(layout.getLayoutComponent(BorderLayout.CENTER));
ninesided
2009-04-17 07:21:48
Cool. Had to modify it a bit, but it worked.Used it in this fashion: myPanel.remove(layout.getLayoutComponent(BorderLayout.CENTER);
Evan Fosmark
2009-04-17 07:40:50
nice one, I've updated my answer to reflect that change
ninesided
2009-04-17 07:47:18
You're both missing the closing parenthesis for the remove function ;)
Tom Martin
2009-04-17 11:07:12
Ensure you you call Container.validate() after you change the components to signal layout manager to recalculate the positions of the components being displayed. In your example it would be panel.validate();
gencoreoperative
2010-05-25 12:11:50