Adding Beans
We will now add the components (beans) that make up our little example applet.
Looking at the proposed GUI we see that we will need
- 3 labels,
- 3 text fields,
- 4 buttons.
The right part of the window (the tools area) contains three panels that we
will need in the following:
- the palette window that shows all beans we can use,
- the inspector window with a hierarchical view of the beans
that have been added to the form (i.e. to the graphical area represented by
the grey rectangle),
- the properties window displaying the properties of the selected
bean.
- First resize the tools area:
- move the mouse over the large horizontal border directly
above the inspector window, the cursor now changes to a double arrow (),
- drag the border down and enlarge the palette window until
you can see two lines of icons,
- enlarge the inspector window in a similar way, using
the border right below it, until all three windows have approximately
the same height,
- drag the vertical border to the left until it almost reaches the form rectangle
to make the whole tools area as wide as possible.
- Change the global layout of the applet from BorderLayout
to Null Layout:
- Locate the JApplet entry
()
in the inspector, open its context menu with a right click and select
Set Layout/Null Layout.
This allows to place all components directly with the mouse.
- Make sure that you are in selection mode:
- If the arrow field in the upper left corner of the form
window is dark grey ():
fine.
- If not: simply click on it.
- Now add the labels to the form:
- Find the JLabel bean ()
in the palette and click on it.
- Click in the grey form rectangle at approximately the
position where the label should be. It is shown immediately with the default
text jLabel1. Additionally it is displayed in
the inspector window.
- Repeat the last two steps twice to add the other labels
- If you like, you can rearrange the labels by dragging
them to their correct positions.
- Finally add the three text fields (JTextField
)
and the four buttons (JButton ).
If you have added a wrong bean, you can delete it by choosing Delete
from its context menu, either directly in the form area or from the inspector.
The result should look like similar to this: