Containers in grid cells

  Traversing the container hierarchy
  JTabbedPane
  JSplitPane
  JScrollPane

The purpose of a container is, to hold other components. First we look at containers in general, then we discuss some special ones.

To add a component to a container, first insert the container in a grid cell and then drag the component to the same cell (if you reverse these two steps, then you apply the container to the component).

You can also convert a (contiguous) selection into a container (one of JPanel, FolderPanel, JDesktopPane or JLayeredPane). You find the appropriate commands in the grid .
In case of JPanel or FolderPanel, the selection is replaced by a panel containing the selection (with JPanel you will see no difference). In case of JDesktopPane or JLayeredPane, the selection is added as the pane's content panel and is then replaced by the pane.


Traversing the container hierarchy     Top of page

To select a component inside a container, maybe to adjust its properties, you can double-click the container or you can select the desired component in the . In both cases you switch to the next hierarchy level.
To return to the top hierarchy level, select 'Grid | To Top Container'.
To step up one hierarchy level, select 'Grid | To Parent Container'.
To switch back to the last displayed container, select 'Grid | To Last Displayed Container'.

The Navigator window

You can view and easily traverse the container hierarchy using the Navigator which displays an overview of the . As you move the mouse over a container icon, this container is marked with a . If you click the mouse, the container (respective its content) will be displayed.


JTabbedPane     Top of page

Whenever you add a component to a tabbed pane, a new tab is generated (showing the variable name of the component) and the component is made the selected component.

To select another tab, to remove a tab from the tabbed pane or to rearrange tabs, select the according menu item from the tabbed pane's .

To access the properties of a single tab (colors, title, icon, mnemonic), select 'Edit Tabs' from the context menu, then the Tab editor opens.

You can apply a FocusTraversalPolicy to containers contained in a tabbed pane (see: Defining a FocusTraversalPolicy).


JSplitPane     Top of page

JSplitPane can hold only two components. The first component you add is added as the top/left component, the second at bottom/right position. If you try to add one more component, a dialog appears, where you can decide to add this component as the splitpane's top/left or bottom/right component (or not at all). The 'Switch Components' command from the splitpane's switches both components.


JScrollPane     Top of page

JScrollPane requires some special care to work as expected.
You should know that a scrollpane's preferred size is calculated from the preferred size of its viewport component, respectively, if the viewport component implements Scrollable, from its preferredScrollableViewportSize.

An (examplary for all components which not implement Scrollable), has a preferred size equal to the image size. This means that, without any additional constraints, the scrollpane would always show the entire image (and therefore wouldn't be very useful). So you should set the preferredSize property of JScrollPane to a value smaller than the image size.
(If you prefer a defined scrolling behaviour you can apply a JPanel to an image label, see the note below.)

A implements Scrollable and has a visibleRowCount property from which JList calculates its preferred height (whereas its preferred width is the width of the widest item in the list). As a consequence, JLists in scrollpanes work perfectly without any additional settings.

A also implements Scrollable and has a visibleRowCount property (which defaults to 20 visible rows). Its preferred width is equal to the width of the widest tree node, but might easily enlarge as you expand nodes. Therefore, for JTree, set the visibleRowCount property to a value which suits your needs, make its grid cell wide enough that nodes will have some place to expand and set the left and right anchors.

A also implements Scrollable and, as the only Swing component, has a preferredScrollableViewportSize property (which defaults to Dimension(450,400)). The preferable way to define the scrollpane's size is via the table's preferredScrollableViewportSize property. (Note: The table header is not included in preferredScrollableViewportSize.)

Note: With RADi, every JPanel implements Scrollable, the scrolling behaviour is defined by a ScrollableDefinition which you access via the scrollableDefinition property of RadiPanel (see The Scrollable definition).

See also:
Internal panels
The runtime library
Defining the FocusTraversalPolicy