JComponent Class
With the exception of top-level containers, all Swing components whose names begin with "J" descend from the JComponent
class. For example, JPanel
, JScrollPane
, JButton
, and JTable
all inherit from JComponent
. However, JFrame
and JDialog
don't because they implement top-level containers. The JComponent
class extends the Container
class, which itself extends Component
. 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. This section's API tables summarize the most often used methods of Component
and Container
, as well as of JComponent
.
JComponent Features
The
JComponent
class provides the following functionality to its descendants:
- Tool tips
- By specifying a string with the
setToolTipText
method, you can provide help to users of a component. When the cursor pauses over the component, the specified string is displayed in a small window that appears near the component. See How to Use Tool Tips for more information.
- Painting and borders
- The
setBorder
method allows you to specify the border that a component displays around its edges. To paint the inside of a component, override the paintComponent
method. See How to Use Borders and Performing Custom Painting for details.
- Application-wide pluggable look and feel
- Behind the scenes, each
JComponent
object has a corresponding ComponentUI
object that performs all the drawing, event handling, size determination, and so on for that JComponent
. Exactly which ComponentUI
object is used depends on the current look and feel, which you can set using the UIManager.setLookAndFeel
method. See How to Set the Look and Feel for details.
- Custom properties
- You can associate one or more properties (name/object pairs) with any
JComponent
. For example, a layout manager might use properties to associate a constraints object with each JComponent
it manages. You put and get properties using the putClientProperty
and getClientProperty
methods. For general information about properties, see Properties.
- Support for layout
- Although the
Component
class provides layout hint methods such as getPreferredSize
and getAlignmentX
, it doesn't provide any way to set these layout hints, short of creating a subclass and overriding the methods. To give you another way to set layout hints, the JComponent
class adds setter methods — setMinimumSize
, setMaximumSize
, setAlignmentX
, and setAlignmentY
. See Laying Out Components Within a Container for more information.
- Support for accessibility
- The
JComponent
class provides API and basic functionality to help assistive technologies such as screen readers get information from Swing components, For more information about accessibility, see How to Support Assistive Technologies.
- Support for drag and drop
- The
JComponent
class provides API to set a component's transfer handler, which is the basis for Swing's drag and drop support. See Introduction to DnD for details.
- Double buffering
- Double buffering smooths on-screen painting. For details, see Performing Custom Painting.
- Key bindings
- This feature makes components react when the user presses a key on the keyboard. For example, in many look and feels when a button has the focus, typing the Space key is equivalent to a mouse click on the button. The look and feel automatically sets up the bindings between pressing and releasing the Space key and the resulting effects on the button. For more information about key bindings, see How to Use Key Bindings.
- -Source:Oracle.com
No comments:
Post a Comment