A pane or panel is a container for other components. It is used
within another pane or panel, within a window, or within an applet.
VisualAge provides pane and panel beans from the
com.sun.java.swing and
java.awt packages. Although Swing and AWT beans can
be mixed, it is inadvisable.
You can add a pane or panel bean as an embedded container for other
components. You can also create a bean as a subclass of one of these
beans to define a reusable component. This is particularly useful for
panels.
- Add or create one of the following pane or panel beans:
- Define initial characteristics of the component.
- Specifying when to display scroll bars in a JScrollPane or ScrollPane bean
- Select a scroll bar policy in the pane's property sheet. For a
JScrollPane bean, set horizontal and vertical scroll bar policies with the
horizontalScrollBarPolicy and verticalScrollBarPolicy
properties. For a ScrollPane bean, set a policy for both scroll bars
with the scrollBarDisplayPolicy property. Select one of the
following choices to specify when to display the scroll bar or scroll
bars:
- ALWAYS or SCROLLBARS_ALWAYS--always display,
regardless of the relative size of the scroll pane and the component it
contains.
- AS_NEEDED or SCROLLBARS_AS_NEEDED--display only
when the scroll pane is smaller than the component it contains. For a
JScrollPane bean, also specify a preferred size for the
preferredSize property.
- NEVER or SCROLLBARS_NEVER--never display,
regardless of the relative size of the scroll pane and the component it
contains
- Enabling scrolling for a null layout in a JScrollPane or ScrollPane bean
- If you use a null layout for a panel that is embedded in a scroll pane,
set the panel's size and preferredSize properties
to support scrolling by the scroll pane.
- Scrolling a JScrollPane bean in the Visual Composition Editor
- You can manipulate the scroll bars in a JScrollPane during composition,
but not by dragging the scroll box (thumb)
- Defining the component orientation in a JSplitPane bean
- Set the orientation property in the pane's property sheet
to arrange components within the split pane. The default setting,
HORIZONTAL, arranges components on the left and right. To
arrange components on the top and bottom, select VERTICAL.
- Adding components to a JSplitPane bean
- You can add two components to a split pane. When you select a
component to add, hold down the mouse button to drag it over one half of the
split pane. When the mouse pointer is over the split pane and before
you release the mouse button, a target outline appears around the half of the
split pane that would receive the component. Drop one component on each
half of the split pane. Before you add the second component, the first
component appears to fill the split pane, but the target outline appears when
you move the mouse pointer over the side of the split pane that does not yet
have a component.
- Defining the divider for a JSplitPane bean
- Set the dividerLocation property to specify the initial
position of the divider between the panes. This has no effect unless
two components have been added to the split pane. Set the
dividerWidth property to specify the initial width of the
divider. Set the oneTouchExpandable property to
True to enable the user to adjust the width of the divider.
- Composing the first tab page of a JTabbedPane bean
- When you drop a JTabbedPane, VisualAge automatically adds a JPanel and
names it Page. Customize this page to serve your purpose. Change
the tab and add the components you want. If you do not want a JPanel as
the page component, delete it and add another component. To avoid
background paint problems when you delete a page, set the opaque
property of the JTabbedPane to True.
- Adding a tab page to a JTabbedPane bean
- Drop the tab page component you want on the tab region of the pane.
If you drop the component on a tab, a tab containing the new component is
inserted after the tab you dropped the component on. If you drop the
component after the last tab in the tab region, the new component is added as
the last tab page.
- Switching the composition focus to a tab page component
- Select a tab page component to work with in any of the following
ways:
- Select on the tab with a mouse. Then, click on the tab page
component to shift the focus from the tabbed pane to the tab page
component.
- Select the tab page component in the Beans List window.
- Defining the tab for a JTabbedPane page
- Define the tab in the property sheet as follows:
- Specify the tab text you want for the tabTitle property.
- By default, tabs are at the top of the pane. If you want the tabs
on a different edge of the pane, select the edge you want in the
tabPlacement property.
- If you want an icon on the tab, select an icon for the tabIcon
property. If the tab can be disabled, you should also specify an icon
for the tabDisabledIcon property.
- If you want tool tip text for the tab, specify the text for the
tabTip property. Tool tip text is useful for expanding on
the tab title to explain what what a tab page provides.
- To change tab colors, set the tabBackground and
tabForeground properties.
- To specify whether the tab page is initially enabled or not, set the
tabEnabled property.
- Composing minor tabs in a JTabbedPane bean
- Add a JTabbedPane bean as a tab component in the primary tabbed
pane. Then, define tab placement for the minor tabs on a different edge
of the nested tabbed pane.
- Customizing a JOptionPane dialog
- For standard dialogs, you can call one of the JOptionPane static methods
without adding a JOptionPane bean. These methods are described in the
task on opening a standard JOptionPane dialog. If you want to customize
a dialog, add a JOptionPane bean as follows:
- Add a JDialog or JInternalFrame bean as the frame for the option
pane.
- Delete the content pane of the frame bean.
- Add the JOptionPane as the content pane for the frame bean.
Then, set customized properties in the pane's property sheet,
including the following:
- Specify the message type. Select one of the following choices for
the messageType property to specify the nature of the
message:
- ERROR_MESSAGE
- INFORMATION_MESSAGE
- WARNING_MESSAGE
- QUESTION_MESSAGE
- PLAIN_MESSAGE
- Specify the option selection. Select one of the following choices
for the optionType property to specify the button choices for the
dialog:
- DEFAULT_OPTION
- YES_NO_OPTION
- YES_NO_CANCEL_OPTION
- OK_CANCEL_OPTION
- To specify an initial option selection, set the initialValue
property
- To provide an initial value for prompted input, set the
initialSelectionValue property
- To specify an icon, set the icon property
- Defining initial properties of a JEditorPane bean
- Define initial properties in the pane's property sheet, including the
following:
- Specify the text content type for the contentType
property. For example, you can specify one of the following:
- text/plain--uses the DefaultEditorKit
- text/html--uses the HTMLEditorKit
- text/rtf--uses the RTFEditorKit
- application/rtf--uses the RTFEditorKit
- Enter any initial text for the text property.
- For HTML, you can specify a document page instead of initial text.
Specify the URL as a quoted string for the page property.
- Specifying a styled document for a JTextPane bean
- Set the styledDocument property in the pane's property
sheet.
- Arranging beans in a JPanel or Panel bean
- Use either of the following methods:
- Use a layout manager to control size and position for beans within the
panel
- Without using a layout manager, place beans approximately where you want
them and use visual composition tools to align them
- Defining tool tip text
- For Swing components, you can specify tool tip text, also known as
fly-over text or hover help. Enter text for the toolTipText
property in the component's property sheet.
- Defining initial availability
- By default, the component is initially enabled for user
interaction. To initially disable the component, set the
enabled property to False in the component's
property sheet.
- Provide runtime logic for the component.
- Opening a standard JOptionPane dialog
- The JOptionPane class provides a set of static methods for standard
dialogs. These methods have several signatures, enabling you to specify
certain dialog characteristics. Call any of these methods by creating
an event-to-code connection and specifying the method as the target.
Standard dialog type
| For a dialog frame, use ...
| For an internal frame, use ...
|
Confirmation dialog
| showConfirmDialog()
| showInternalConfirmDialog()
|
Input dialog
| showInputDialog()
| showInternalInputDialog()
|
Message dialog
| showMessageDialog()
| showInternalMessageDialog()
|
General dialog with all of the preceding elements
| showOptionDialog()
| showInternalOptionDialog()
|
The code should process any selected options or requested input.
Depending on the dialog type, the following options can be selected by the
user and returned from the dialog:
- YES_OPTION--the user selected the Yes button
- NO_OPTION--the user selected the No button
- CANCEL_OPTION--the user selected the Cancel
button
- OK_OPTION--the user selected the OK button
- CLOSED_OPTION--the user explicitly closed the frame
- Opening and closing a customized JOptionPane dialog
- If you add a JOptionPane bean for customization, process the dialog as
follows:
- Open the pane's frame to display the dialog. Connect an event
to the frame's show() method.
- Close the pane's frame when the user selects an option to close the
dialog. Connect the pane's propertyChange event to the
frame's setVisible() method. Then, set
the connection parameter to False.
- Connect the pane's propertyChange event to a property to
retrieve an option or input value. Connect the parameter for the
event-to-property connection to one of the following option pane
properties:
- value--the selected option
- inputValue--the requested input value
- Disabling or enabling a component
- Connect a related event to the button's enabled
property. Specify the parameter value for this connection in one of the
following ways:
- To disable the component, open the connection's properties and set
the parameter value to False.
- To enable the component, open the connection's properties and set the
parameter value to True.
- To set the new state from another Boolean property, connect the parameter
to the other Boolean property.
For examples, see the CustomerInfo, AddressView, and
CustomerView classes in the
com.ibm.ivj.examples.vc.customerinfo
package, and the DirectoryExplorer class in the
com.ibm.ivj.examples.vc.swing.directoryexplorer
package. The AddressView and CustomerView classes
subclass a Panel as a reusable bean. The
showMessageBox() method of the
CustomerInfo class uses a JOptionPane. The
DirectoryExplorer class uses a JSplitPane. These examples
are shipped in the IBM Java Examples project.
Working with Beans Visually
Using VisualAge Beans in Visual Composition
Adding the IBM Java Examples project
Pane and Panel Beans
CustomerInfo Sample
