Java Reference
In-Depth Information
Components are not placed directly on a JFrame. Instead, a JFrame must have a content pane on which the
components are added. Notice that there is a JPanel variable called jContentPane (defined on line 14) and that in
the initialize method (line 49) the JContentPane property is set to the JPanel object (created and returned by the
getJContentPane method). So, a JFrame is a little more complicated than a Frame because it needs a content pane.
However, the Visual Editor hides this from the programmer by creating a JPanel and assigning it to the JFrame's
content pane property.
6.
In the Visual Editor Design pane, watch the properties view and click on the content pane
area (center of the JFrame).
Notice that the properties change. This is because the JFrame and JPanel are two different classes with
different properties.
7.
In the Swing Components tray, click on JCheckBox and move the mouse cursor over
the panel.
Notice how the panel “lights up” with various sections. This occurs because the JPanel has a default layout of
BorderLayout (just like Frame).
8.
In the Properties view, change the JPanel Layout property to null and press Enter.
9.
Place a JCheckBox on the panel and accept the default name.
Notice that there are quite a few more JCheckBox properties than there are AWT checkbox properties. Many of
these properties are very useful. For instance, flyover text can be defined (the toolTipText property) or a keystroke
shortcut can be assigned (the mnemonic property).
10.
Specify “Starts Shipment Application” for the toolTipText property.
11.
Click on the mnemonic property to display the Java Property Editor button.
12.
Click on the Java Property Editor button to display the Java Property Editor.
You can scroll through the list of options and select a key. Selecting a key as a shortcut means that the selected
key when pressed with the Alt key will automatically select the check box.
13.
From the list, select B.
14.
Click the OK button and save AppOptionsSwing.
15.
Create a Java class called TNTSwing that creates an AppOptionsSwing object and assigns it
to variable aos.
16.
Run TNTSwing.
Nothing happened—why? We never changed the AppOptionsSwing's visible property to true!
17.
Change the AppOptionsSwing's visible property to true and run TNTSwing.
18.
Move the mouse cursor over the JCheckBox.
Notice the flyover text is displayed.
19.
Press and hold the Alt key and then press the B key.
Notice that the checkbox has been checked.
20.
Close the JFrame.
 
Search WWH ::




Custom Search