|
Swing
Introduction
This
tutorial describes some basic Swing components.
Introduction
JComponent
Class
Some
Swing Components
Introduction
Many Swing components
are available to us for developing applications and applets with graphical user
interfaces. We can have components such as JLabels and JToolTips
that exist to present information to the user. We can also have components
such as JButtons, JTextFields, JCheckBoxes
and JRadioButtons that exist to get input from the
user.
These component
classes come with many useful methods of their own but other useful methods are
inherited from parent classes.
JComponent
Class
Almost all Swing
components inherit from the JComponent class. The diagram
below shows the class inheritance structure.

Some
useful methods of the JComponent class that are inherited by
components such as JButton etc. are setToolTipText, setBorder
and getBorder, setForegroundColor and getForegroundColor,
setBackground and getBackground and setEnabled.
This is not a comprehensive list of the methods of the JComponent
class, there are many more useful methods.
Also, JComponent
inherits from Container and Component which provide
many useful methods. The Component class includes everything from
providing layout hints to supporting painting and events. The Container
class has support for adding components to the container and laying them out.
Some
Swing Components
The Swing
components we will consider in this tutorial are:-
|
|
an
area that triggers an event when clicked
|
|
|
an
area where non-editable text can be displayed
|
|
|
an area in which the user inputs
data from the keyboard
|
|
|
an area for manipulating multiple lines of text.
|
|
|
presents
the user with a list of items displayed in column
|
|
|
provides
a list of items from which the user can make a selection
|
|
|
a
state button that have on/off, true/false values
|
|
|
a
group of buttons where only one button in the group can be true
|
There are other
Swing components which will not be covered in this tutorial, such as JScrollPane,
JProgressBar, JSlider amongst others.
|