Removing the CENTER element from a JPanel using BorderLayout

Evan Fosmark picture Evan Fosmark · Apr 17, 2009 · Viewed 19.4k times · Source

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?

Answer

ninesided picture ninesided · Apr 17, 2009

Something like this?

BorderLayout layout = (BorderLayout)panel.getLayout();
panel.remove(layout.getLayoutComponent(BorderLayout.CENTER));