Java Reference
In-Depth Information
with SpringLayout s, and we make use of it to format the labels and text fields
relative to each other.
Similar to a JTextField is a JPasswordField . It behaves just like a
JTextField but instead of showing the characters that the user types it shows,
by default, an asterisk for each character typed, thereby hiding the password
from passers-by. The character that is displayed can be changed to other than
the asterisk—see the Javadoc page.
We do something new with our JLabel in AcctDialog , too. We mess
with its font:
44 Font font = label.getFont();
45 label.setFont(label.getFont().deriveFont(font.PLAIN, 14.0f));
This gets the font from the label, however it might have been set, then
creates a new value for the font, keeping whatever font family it might have
been, but making it 14 pt plain (not italic, not bold).
We also put HTML text in the JLabel :
40 JLabel label = new JLabel("<html><p align=left><i>"
41 + "Enter the info to create a subaccount.<br>"
42 + "</i>");
All but the oldest versions of Swing will display the HTML text as it would
be formatted by a browser. Here, we make the text italic by means of the (now
deprecated) <i> tag, thereby undoing the effort to make it plain in lines 44
and 45.
One of the arguments to the dialog's constructor is the JFrame inside
which the dialog will appear. Lines 102 and 103 round out this picture, setting
the size of the dialog and anchoring its position relative to the parent frame.
The last step for the constructor is to make the dialog visible, thereby passing
control to it.
16.8
R EVIEW
When programming in Swing, we create the GUI objects and then let Swing
do the work of managing all the interactions. We created:
Search WWH ::




Custom Search