Java Reference
In-Depth Information
JLabel
A JLabel is a component for placing text in a container. Its primary use is to
label other components such as a JComboBox , JList , JTextField , or JPanel
(many other components already have their names displayed in some way). In
Figure B.1, the phrases Shape , X Coor , and Y Coor are labels. A JLabel is con-
structed with an optional String and can be changed with the method setText .
These methods are
A JLabel is a com-
ponent for placing
text in a container.
Its primary use is to
label other compo-
nents.
JLabel( );
JLabel( String theLabel );
void setText( String theLabel );
JButton
The JButton is used to create a labeled button. Figure B.1 contains a JButton
with the label Draw . When the JButton is pushed, an action event is generated.
Section B.3.3 describes how action events are handled. The JButton is similar
to the JLabel in that a JButton is constructed with an optional String . The
JButton label can be changed with the method setText . These methods are
The JButton is used
to create a labeled
button. When it is
pushed, an action
event is generated.
JButton( );
JButton( String theLabel );
void setText( String theLabel );
void setMnemonic( char c );
JComboBox
The JComboBox is used to select a single object (typically a string) via a pop-up
list of choices. Only one choice can be selected at any time, and by default
only an object that is one of the choices can be selected. If the JComboBox is
made editable, the user can type in an entry that is not one of the choices. In
Figure B.1, the type of shape is a JComboBox object; Circle is currently
selected. Some of the JComboBox methods are
The JComboBox is
used to select a
single string via a
pop-up list of
choices.
JComboBox( );
JComboBox( Object [ ] choices );
void addItem( Object item );
Object getSelectedItem( );
int getSelectedIndex( );
void setEditable( boolean edit );
void setSelectedIndex( int index );
A JComboBox is constructed with no parameters or with an array of
options. Object s (typically strings) can then be added to (or removed from) the
list of JComboBox options. When getSelectedItem is called, an Object represent-
ing the current selected item (or null , if no choice is selected) is returned.
 
Search WWH ::




Custom Search