Java Reference
In-Depth Information
Note
If a text field is used for entering a password, use JPasswordField to replace
JTextField . JPasswordField extends JTextField and hides the input text
with echo characters (e.g., ******). By default, the echo character is *. You can specify
a new echo character using the setEchoChar(char) method.
JPasswordField
12.35 How do you create a text field with 10 columns and the default text Welcome to
Java ? How do you write the code to check whether a text field is empty?
12.36 How do you create text field for entering passwords?
Check
Point
K EY T ERMS
layout manager 451
lightweight component
AWT 446
component class 446
container class 446
heavyweight component
446
Swing components
446
splash screen 467
top-level container
446
447
helper class
446
C HAPTER S UMMARY
1. Every container has a layout manager that is used to position and place components
in the container in the desired locations. Three simple and frequently used layout
managers are FlowLayout , GridLayout , and BorderLayout .
2. You can use a JPanel as a subcontainer to group components to achieve a desired layout.
3. Use the add method to place components in a JFrame or a JPanel . By default, the
frame's layout is BorderLayout , and the JPanel 's layout is FlowLayout .
4. Colors are made of red, green, and blue components, each represented by an unsigned
byte value that describes its intensity, ranging from 0 (darkest shade) to 255 (lightest
shade). This is known as the RGB model .
5. To create a Color object, use new Color(r, g, b) , in which r , g , and b specify a
color by its red, green, and blue components. Alternatively, you can use one of the 13
standard colors ( BLACK , BLUE , CYAN , DARK_GRAY , GRAY , GREEN , LIGHT_GRAY ,
MAGENTA ,
ORANGE ,
PINK ,
RED ,
WHITE ,
YELLOW ) defined as constants in
java.awt.Color .
6. Every Swing GUI component is a subclass of javax.swing.JComponent , and
JComponent is a subclass of java.awt.Component . The properties font ,
background , foreground , height , width , and preferredSize in
Component are inherited in these subclasses, as are toolTipText and border in
JComponent .
7.
You can use borders on any Swing components. You can create an image icon using the
ImageIcon class and display it in a label and a button. Icons and borders can be shared.
8. You can display a text and icon on buttons ( JButton , JCheckBox , JRadioButton )
and labels ( JLabel ).
9. You can specify the horizontal and vertical text alignment in JButton , JCheckBox ,
JRadioButton , and JLabel , and the horizontal text alignment in JTextField .
 
 
Search WWH ::




Custom Search