Re: Why use panels
From: FISH (joeking_at_merseymail.com)
Date: 25 Jun 2004 08:48:40 -0700
V S Rawat <firstname.lastname@example.org> wrote in message news:<40DAAF9B.email@example.com>...
> I have seen some programs in which components like,
> JButtons, JComboboxes, JLabels etc were first added on
> JPanels and then these panels were put in gridbaglayout.
> Does such placement provide some benefit or functionality
> that would not have been available if those components were
> directly put on the gridbaglayout without using JPanels?
> Regards and Thanks in advance.
When building a complicated user interface, it is often easier to break
it up into sections. Gridbag is easily the most powerful layout manager
which comes with Java as standard, but it is also the most complex
(hardly surprising!). Quite often it is easier to build and maintain a
UI when different managers are mixed and nested - even when using some-
thing as powerful as gridbag (which could probably emulate most of the
other managers if given the correct options!)
Also, there are occasions when panels do more than just lay out
components. Back in the pre-Swing days the only way to add a border
around a section of your user interface was to create a panel which
displayed a border, for example. Swing too has its own specialist
containers, many of its 'Pane' components are (strictly speaking)
containers, for example JScrollPane and JSplitPane.