Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the CENTER element from a JPanel using BorderLayout

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?

like image 944
Evan Fosmark Avatar asked Apr 17 '09 07:04

Evan Fosmark


People also ask

What does BorderLayout do in Java?

A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH , SOUTH , EAST , WEST , and CENTER .

What are the areas of a BorderLayout used for?

The BorderLayout is used to arrange the components in five regions: north, south, east, west, and center. Each region (area) may contain one component only. It is the default layout of a frame or window.

What is BorderLayout manager in Java?

BorderLayout is the default layout for the window objects such as JFrame, JWindow, JDialog, JInternalFrame etc. BorderLayout arranges the components in the five regions. Four sides are referred to as north, south, east, and west. The middle part is called the center.


1 Answers

Something like this?

BorderLayout layout = (BorderLayout)panel.getLayout(); panel.remove(layout.getLayoutComponent(BorderLayout.CENTER)); 
like image 104
ninesided Avatar answered Sep 21 '22 04:09

ninesided