You can perform the following advanced tasks to modify your beans:
The tabbing order specifies how the input focus moves from bean to bean as the user presses the Tab key.
You can also change the tabbing order by moving the beans in the Beans List.
If you want to connect to the features of a bean that is embedded within a composite, you must promote bean features. To promote the bean features:
When you promote features, VisualAge performs the following tasks:
When you embed this bean within another bean, the features that you promoted are listed under the type in the Connectable Features window. Connect the promoted feature of each bean to effect the change you desire.
If you want to gain access to an encapsulated feature of a bean, you must tear off the property. To tear off a property:
You can assign a layout manager before or after dropping components on your container bean. However, if you change the layout manager after dropping components, it may affect bean placement.
To set a layout manager in a container bean, follow these steps:
The complexity of this task depends on which layout manager you choose for your container bean and how much custom behavior your bean requires. Default behavior exists to some extent for all layouts. To set layout properties for the components of the container bean, follow these steps:
Consider waiting to set layout properties until you have settled on a layout manager. Many values are lost when you switch layouts or move the component to another container.
GridBagLayout is a powerful tool for layout, however,
because of its many choices, it can become confusing. Once you have
selected GridBagLayout for your user interface, adjust the constraints from
the property sheet or the Layout Options from the pop-up
to affect the placement and resize behavior of beans within the layout.
Constraint | Specifies... |
---|---|
Anchor | Where within the cell (North, South, etc.) to place a component that is smaller than the cell. |
Fill | How to size the component (Vertical, Horizontal, Both, or None) when the cell is larger than the component's requested size. |
gridX, gridY | The column (gridX) and row (gridY) where your component resides. If gridWidth or gridHeight is >1, gridX and gridY are the starting row and column. The default places a new component to the right or below the previously added component. |
gridWidth, gridHeight | The number of cells the component should use in a row (gridWidth) or column (gridHeight). |
insets | The component's external padding, the minimum amount of space between the component and the edges of its cell. |
ipadX, ipadY | The component's internal padding within the layout, or how much to add to the width and/or height of the component. |
weightX, weightY | How to redistribute space for resizing behavior. You should specify a weight for at least one component in a row (weightX) and column (weightY) to prevent all the components from clumping together in the center of their container. The distribution of extra space is calculated as a proportional fraction of the total weightX in a row and weightY in a column. |
Unlike in other layout managers, in GridBag you set constraints on individual components within the layout and not on the layout itself. Also unlike other layout managers, GridBag enables you to set constraints so that the size of the components adjusts as you resize the runtime program.
Resize behavior in GridBagLayout is tied to the weightX, weightY, and fill contstraints of components within the layout. By default, the component properties are set without resize behavior. If you place components in any layout and then change the layout to GridBag, the component constraints are set to maintain the look created in the original layout.
To set constraints so that components increase and decrease as you resize the runtime program, you must:
You can perform these adjustments from the constraints on the property sheet or from Layout Options on the component pop-up.
Follow these steps to create a To Do List GUI using GridBagLayout:
Note: | These windows are necessary for modifying properties and accessing covered components throughout this process. |
Note: | Beans dropped in GridBagLayout appear in their preferred size. The preferred size, which is different for every component, is usually dependent on one of the component's property settings. For example, the preferred size of JLabel is the size of the text within the label. If the component is a container, like a JPanel or a JScrollPane, the preffered size usually reflects the preffered size of the contents of the component. |
Bean... | Property... | Change Value to... | What You See.. |
---|---|---|---|
JTextField1 | columns | 5 | TextField width increase |
JLabel1 | text | To Do Item: | Change in text |
JLabel2 | text | To Do List | Change in text |
JLabel2 | font | Name=serif, Size=18 | Change in font style and size |
JLabel2 | horizontalAlignment | center | Label placement is centered |
Note: | Since the JScrollPane, not the JList, is the component that is sitting in the GridBagLayout, you modify its constraints. Because the JList completely covers the JScrollPane, you must select the pane from either the Beans List window or the Properties window. If you select the JList instead, you cannot adjust the component width within the layout manager. |
Bean... | Constraint... | Change Value To... | What You See.. |
JScrollPane1 | gridWidth | 2 | Pane covers two cells width |
JScrollPane1 | fill | both | Pane fills the cell vertically and horizontally |
JScrollPane1 | weightX | 1 | Column containing the JScrollpane expands to fill the extra horizontal space in the JApplet |
JScrollPane1 | weightY | 1 | Row containing the JScrollpane expands to fill the extra vertical space in the JApplet |
JScrollPane1 | insets | left=15, bottom=5, right=15 | Padding on the left, bottom, and right of the pane |
JLabel2 | gridWidth | 2 | Label covers two cells width |
JLabel2 | insets | top=15 | Padding on the top of the label |
JTextField1 | fill | horizontal | Textfield fills cell horizontally |
JTextField1 | insets | top=15, bottom=5, right=15 | Padding around top, bottom and right side of the TextField |
JLabel1 | ipadX | 10 | Internal padding between text and component border |
JLabel1 | insets | top=15, left=15, bottom=5, right=5 | Padding around all sides of label |
Note: | Setting the weightX and weightY on the JScrollPane, insures that the GUI resizes proportionately. Setting the ipadX on JLabel1, insures that the label resizes proportionately. This is especially helpful when translating your GUI into other languages. |
Bean... | Property... | Change Value To... | What You See... |
---|---|---|---|
JPanel1 | constraints--anchor | EAST | Panel placement moves to the lower right corner |
JPanel1 | constraints--insets | bottom=15, right=15 | Padding around the right and bottom of the panel |
JPanel1 | layout--hgap | 5 | Space between the buttons |
JButton1 | text | Add | Button label changes |
JButton2 | text | Remove | Button label changes |
Morphing allows you to perform the following tasks:
To morph a bean:
To preserve cross-platform portability, Swing components use the Metal look and feel. You can change the appearance of these components during visual composition through the use of a .properties file.
swing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
You must enter the swing.defaultlaf constant exactly as shown, but you can specify any valid look-and-feel class after the equals sign.
VisualAge scans the program\lib directory for the existence of this file every time a new Visual Composition Editor is opened. Consequently, any that are already open at the time you save the file will not be affected.
Bean morphing
Promotion of bean features
Visual Composition Editor overview
Layout managers in visual composition
Tabbing order
Torn-off properties
Editing bean properties
Promote bean feature
Promote Features window
Visual Composition Editor
Pop-up menus for the Visual Composition Editor
Properties