A pane or panel is contained by another pane, panel, window, or applet and is itself a container for other components. VisualAge provides pane and panel beans from the com.sun.java.swing and java.awt packages.
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.
Bean | Description |
---|---|
JDesktopPane (Swing) | A pane for a desktop within another Swing container |
JEditorPane (Swing) | A pane for editing defined text types, such as HTML |
JOptionPane (Swing) | A simple dialog pane |
JPanel (Swing) or Panel (AWT) | A composition surface for user interface components |
JScrollPane (Swing) or ScrollPane (AWT) | A scrollable view for another component |
JSplitPane (Swing) | A split view for other components |
JTabbedPane (Swing) | A tabbed view for other components |
JTextPane (Swing) | A pane for editing text with visible styles and embedded objects |
Bean--specific tasks
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.
Visual bean basics
Using VisualAge beans in visual composition
Adding the IBM Java Examples project
Pane and panel beans
CustomerInfo sample
Displaying scroll bars
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:
Property Value | Description |
---|---|
ALWAYS or SCROLLBARS_ALWAYS | Display, regardless of the size of the scroll pane or 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 property. |
NEVER or SCROLLBARS_NEVER | Never display, regardless of the size of the scroll pane or the component it contains. |
Enabling scrolling for a null layout
If the panel that you embedded in a scroll pane uses a null layout, you must set its preferredSize property to support scrolling. Set this property so that the panel is larger than the scroll pane.
Scrolling a JScrollPane bean in the Visual Composition Editor
You can manipulate the scroll bars in a JScrollPane during composition by clicking the pointer on either size of the scroll box (thumb), but not by dragging.
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 only add two components to a split pane: one component on each half. Select the component you want to add and drag it to the split pane. Before you release the mouse button, an outline appears around the target pane. When you release it, the first component appears to fill the split pane. However, the target outline appears when you move the loaded pointer over the empty side of the split pane.
Defining the divider for a JSplitPane bean
Set the dividerLocation property to specify the initial divider position. This is only affective if you have two components in 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
A JTabbedPane contains a default JPanel, named Page. You can customize this page by changing the tab and adding the components you want. You can change the default JPanel and add another container 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 component you want onto the tab region of the pane tab page. If you drop the component on a tab, VisualAge inserts a tab containing the new component after the tab you dropped the component on. If you drop the component after the last tab in the tab region, VisualAge inserts the new component as the last tab page.
Switching the composition focus to a tab page component
You can use the following methods to work with a tab page component:
Defining the tab for a JTabbedPane page
Define the tab in the property sheet as follows:
Property | Description |
---|---|
tabTitle | Text for the tab |
tabPlacement | Move tab from default position |
tabIcon | Specify an icon for the tab |
tabDisabledIcon | Specify an icon for the disabled state |
tabTip | Provide tool tip text for the tab |
tabBackground and tabForeground | Change tab colors |
tabEnabled | Set the initial state of the tab |
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.
Defining initial properties of a JEditorPane bean
Define initial properties in the pane's property sheet, including the following:
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:
Customize properties in the pane's property sheet, including the following:
Property | Possible Values |
messageType | ERROR_MESSAGEINFORMATION_MESSAGE WARNING_MESSAGEQUESTION_MESSAGE PLAIN_MESSAGE |
optionType | DEFAULT_OPTIONYES_NO_OPTIONYES_NO_ CANCEL_OPTIONOK_CANCEL_OPTION |
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 user can select the option and have the corresponding option returned from the dialog.
Opening and closing a customized JOptionPane dialog
If you add a JOptionPane bean for customization, process the dialog as follows: