Java Reference
In-Depth Information
12.19
How do you create a Font object with font name Courier , size 20 , and style bold ?
Check
12.20
Point
How do you find all available fonts on your system?
12.9 Common Features of Swing GUI Components
GUI components have common features. They are defined in the superclasses
Component , Container , and JComponent .
So far in this chapter you have used several GUI components (e.g., JFrame , Container ,
JPanel , JButton , JLabel , and JTextField ). Many more GUI components will be
introduced in this topic. It is important to understand the common features of Swing GUI
components. The Component class is the root for all GUI components and containers. All
Swing GUI components (except JFrame , JApplet , and JDialog ) are subclasses of
JComponent , as shown in Figure 12.1. Figure 12.11 lists some frequently used methods in
Component , Container , and JComponent for manipulating properties such as font,
color, mouse cursor, size, tool tip text, and border.
A tool tip is text displayed on a component when you move the mouse onto the component.
It is often used to describe the function of a component.
Key
Point
VideoNote
Use Swing common properties
Component
Container
JComponent
tool tip
The get and set methods for these data
fields are provided in the class, but
omitted in the UML diagram for brevity.
java.awt.Component
-font: java.awt.Font
-background: java.awt.Color
-foreground: java.awt.Color
-preferredSize: java.awt.Dimension
The font of this component.
The background color of this component.
The foreground color of this component.
The preferred size of this component.
Indicates whether this component is visible.
The mouse cursor shape.
Returns the width of this component.
Returns the height of this component.
getX() and getY() return the coordinate of the
component's upper-left corner within its parent component.
-visible: boolean
-cursor: java.awt.Cursor
+getWidth(): int
+getHeight(): int
+getX(): int
+getY(): int
java.awt.Container
+add(comp: Component): Component
+add(comp: Component, index: int): Component
+remove(comp: Component): void
+getLayout(): LayoutManager
+setLayout(l: LayoutManager): void
Adds a component to the container.
Adds a component to the container with the specified index.
Removes the component from the container.
Returns the layout manager for this container.
Sets the layout manager for this container.
The get and set methods for these data
fields are provided in the class, but
omitted in the UML diagram for brevity.
javax.swing.JComponent
-toolTipText: String
The tool tip text for this component. Tool tip text is displayed when
the mouse points on the component without clicking.
The border for this component.
-border: javax.swing.border.Border
F IGURE 12.11
All the Swing GUI components inherit the public methods from Component , Container , and
JComponent .
 
 
 
Search WWH ::




Custom Search