Java Reference
In-Depth Information
figure B.2
Compressed
hierarchy of Swing
Component
Container
Window
JComponent
JButton
JCheckBox
Frame
JComboBox
JFrame
JLabel
JPanel
JList
JRadioBox
JTextArea
JTextField
B.2.1 Component
The Component class is an abstract class that is the superclass of many AWT
objects, and thus Swing objects. Because it is abstract, it cannot be instanti-
ated. A Component represents something that has a position and a size and can
be painted on the screen as well as receive input events. Some examples of the
Component are evident from Figure B.2.
The Component class contains many methods. Some of these can be used to
specify the color or font; others are used to handle events. Some of the impor-
tant methods are
The Component
class is an abstract
class that is the
superclass of many
AWT objects. It rep-
resents something
that has a position
and a size and can
be painted on the
screen as well as
receive input
events.
void setSize( int width, int height );
void setBackground( Color c );
void setFont( Font f );
void setVisible( boolean isVisible );
The setSize method is used to change the size of an object. It works with
JFrame objects, but it should not be called for objects that use an automatic
layout, such as JButton s. For those, use setPreferredSize ; this method takes a
Dimension object that itself is constructed with a length and width (and is
 
 
Search WWH ::




Custom Search