CardPanel
A CardPanel is not a Swing container on itself but a JPanel with a CardLayout layout manager, resulting in a "tabbed pane without tabs". You can switch the different cards programmatically like this:
|
// create a JPanel with CardLayout
JPanel cardPanel = new JPanel(new CardLayout());
// add some components to the panel, the second
// argument is a String which identifies the card
cardPanel.add(component1, "card1");
cardPanel.add(component2, "card2");
cardPanel.add(component3, "card3");
// display an arbitrary card, the second argument
// to show() is the identifier
((CardLayout)cardPanel.getLayout()).show(cardPanel, "card2");
|
|
There are dialogs for editing the CardLayout 's constraints and for rearranging cards.
You can also define a controller component for a card panel. Every JComboBox , JList or JTree whose number of items (rows) match the number of cards, can be a controller. Select 'Define Controller' from the card panel's context menu. In the 'Define Controller' dialog you can select an appropriate controller and map controller items to cards.
|
| |
|
Context menu
| |
'Define Controller' dialog
|
|
Note: It is possible to control several card panels with one controller. See example layout 26 Eclipse Project Properties where the tree at the left controls the card panel.
|
To select another card, to remove a card, to rearrange cards or to edit the constraints (identifiers), select the according menu item from the card panel's context menu.
|
|
CardPanel's context menu
|
Note: You can switch from CardPanel to JTabbedPane and vice versa at every time without affecting the number or order of child components.
|
| |
|
|