Advanced visual bean tasks

You can perform the following advanced tasks to modify your beans:

Setting the tabbing order

The tabbing order specifies how the input focus moves from bean to bean as the user presses the Tab key.

  1. Open the pop-up menu for the composite bean.
  2. Select Set tabbing and then Show tab tags and numbered tab tags appear.
  3. Place the mouse pointer over the tab tag you want to change.
  4. Press and hold mouse button 1.
  5. Drag the tab tag to its new position.
  6. Release mouse button 1.
  7. Repeat until the numbered tags reflect the desired tabbing order.

You can also change the tabbing order by moving the beans in the Beans List.

Promoting bean features

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:

  1. Open the bean pop-up.
  2. Select Promote bean feature.
  3. Select the type of feature: Method, Property, or Event.
  4. From the list box, select the feature you want to promote and >> is enabled.
  5. Click >>. The feature appears in the Promoted features list.
  6. Repeat for the other features you wish to promote.
  7. If you wish to rename the feature, double-click and modify the name listed in the Promote Name list.
  8. If you wish to remove the feature from the Promoted features list, click <<.
  9. Click OK.

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.

Tearing off properties

If you want to gain access to an encapsulated feature of a bean, you must tear off the property. To tear off a property:

  1. Select Tear off property from the pop-up menu of the bean with the property you want to access. Another menu appears listing all of the properties of the bean.

  2. Select the property you want to tear off. The mouse pointer is now loaded with a variable bean representing or pointing to the property you selected.

  3. Place the new bean on the free-form surface, as you would any other nonvisual bean. The torn-off property now appears as a variable bean connected to the original bean by a property-to-property connection.

Setting a layout manager during visual composition

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:

  1. Open the property sheet for the container bean.
  2. From the value column, select the cell for the layout property.
  3. From the Layout Manager drop-down list, select a layout.

Setting layout properties during visual composition

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:

  1. Open the property sheet for the component bean.
  2. If one exists, click the expansion icon Expansion Icon to the left of the constraints property.
  3. Select the value field for the property you want to modify and enter the new property value.
  4. Press enter to apply the value.

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 constraints

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.

Achieving the resize behavior you want

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:

  1. Apply a weightX, such as 1.0, to a component in a row.
  2. Apply a weightY, such as 1.0, to a component in a column.
  3. Apply the appropriate fill value for each component in the container you wish to resize. For example, if you want the component to resize only in the horizontal direction, select the horizontal fill for that component.
  4. If the calculated inset padding is not appropriate, adjust the inset values.

You can perform these adjustments from the constraints on the property sheet or from Layout Options on the component pop-up.

Creating a GUI using GridBagLayout

Follow these steps to create a To Do List GUI using GridBagLayout:


To Do List in GridBagLayout

  1. To set up the applet:

  2. To place beans in the GridBag:

  3. To adjust property values within the Properties window, select the bean and then adjust the property value:
    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

  4. To adjust the constraints properties within the Properties window, select the bean and then open the constraints tree-view and adjust the property value :
    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.

  5. To add the button panel:

  6. To adjust the properties and constraints properties for JPanel1 and its contents:
    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 beans

Morphing allows you to perform the following tasks:

To morph a bean:

  1. Select the bean you want to morph.
  2. Open the bean pop-up and select Morph Into.
  3. Select the bean type and use Browse to select the class.
  4. Click OK.

Changing look and feel in Swing-based composites

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.

  1. Create the file swing.properties in your favorite text editor. An example for Windows look and feel follows:
    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.

  2. Save the file in the program\lib directory of your VisualAge installation.

    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.


Related concepts
Bean morphing
Promotion of bean features
Visual Composition Editor overview
Layout managers in visual composition
Tabbing order
Torn-off properties

Related procedures
Editing bean properties

Related references
Promote bean feature
Promote Features window
Visual Composition Editor
Pop-up menus for the Visual Composition Editor
Properties