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
.
The JComponent
class provides the following functionality to its descendants:
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.
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.
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.
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.
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.
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.
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.
The JComponent
class provides many new methods and inherits many methods from Component
and Container
. The following tables summarize the methods we use the most.
int
arguments specify x and y coordinates, respectively. Component getComponentAt(int, int)
Component.contains()
. Component setComponentZOrder(component comp, int index)
If the component is a child of some other container, it is removed from that container before being added to this container. The important difference between this method and java.awt.Container.add(Component, int)
is that this method doesn't call removeNotify
on the component while removing it from its previous container unless necessary and when allowed by the underlying native windowing system. This way, if the component has the keyboard focus, it maintains the focus when moved to the new position.
Note: The z-order determines the order that components are painted. The component with the highest z-order paints first and the component with the lowest z-order paints last. Where components overlap, the component with the lower z-order paints over the component with the higher z-order.
JComponent
subclasses, which do not have the corresponding setter methods, you can set a component's preferred, maximum, or minimum size by creating a subclass and overriding these methods. void setAlignmentX(float)
JComponent
subclasses, which do not have the corresponding setter methods, you can set a component's alignment by creating a subclass and overriding these methods. void setLayout(LayoutManager)
ComponentOrientation
property of this container and all the components contained within it. See Setting the Container's Orientation for more information. Specifying Absolute Size and Positionint
arguments specify x and y, in that order. Use these methods to position a component when you are not using a layout manager. void setSize(int, int)
int
arguments specify width and height, in that order. Use these methods to size a component when you are not using a layout manager. void setBounds(int, int, int, int)
int
arguments specify x, y, width, and height, in that order. Use these methods to position and size a component when you are not using a layout manager.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3