Java javax.swing JComponent fields, constructors, methods, implement or subclass

Example usage for Java javax.swing JComponent fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for javax.swing JComponent.

The text is from its open source code.

Subclass

javax.swing.JComponent has subclasses.
Click this link to see all its subclasses.

Field

intWHEN_FOCUSED
Constant used for registerKeyboardAction that means that the command should be invoked when the component has the focus.
intWHEN_ANCESTOR_OF_FOCUSED_COMPONENT
Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.
intWHEN_IN_FOCUSED_WINDOW
Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component.

Constructor

JComponent()
Default JComponent constructor.

Method

Componentadd(Component comp)
Appends the specified component to the end of this container.
Componentadd(String name, Component comp)
Adds the specified component to this container.
voidaddAncestorListener(AncestorListener listener)
Registers listener so that it will receive AncestorEvents when it or any of its ancestors move or are made visible or invisible.
voidaddComponentListener(ComponentListener l)
Adds the specified component listener to receive component events from this component.
voidaddFocusListener(FocusListener l)
Adds the specified focus listener to receive focus events from this component when this component gains input focus.
voidaddHierarchyListener(HierarchyListener l)
Adds the specified hierarchy listener to receive hierarchy changed events from this component when the hierarchy to which this container belongs changes.
voidaddKeyListener(KeyListener l)
Adds the specified key listener to receive key events from this component.
voidaddMouseListener(MouseListener l)
Adds the specified mouse listener to receive mouse events from this component.
voidaddMouseMotionListener(MouseMotionListener l)
Adds the specified mouse motion listener to receive mouse motion events from this component.
voidaddPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.
voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list for a specific property.
voidaddVetoableChangeListener(VetoableChangeListener listener)
Adds a VetoableChangeListener to the listener list.
ImagecreateImage(ImageProducer producer)
Creates an image from the specified image producer.
voiddoLayout()
Causes this container to lay out its components.
booleanequals(Object obj)
Indicates whether some other object is "equal to" this one.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this Component .
ActionMapgetActionMap()
Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding.
AncestorListener[]getAncestorListeners()
Returns an array of all the ancestor listeners registered on this component.
ColorgetBackground()
Gets the background color of this component.
BordergetBorder()
Returns the border of this component or null if no border is currently set.
RectanglegetBounds()
Gets the bounds of this component in the form of a Rectangle object.
ClassgetClass()
Returns the runtime class of this Object .
ObjectgetClientProperty(Object key)
Returns the value of the property with the specified key.
ComponentgetComponent(int n)
Gets the nth component in this container.
intgetComponentCount()
Gets the number of components in this panel.
ComponentListener[]getComponentListeners()
Returns an array of all the component listeners registered on this component.
ComponentOrientationgetComponentOrientation()
Retrieves the language-sensitive orientation that is to be used to order the elements or text within this component.
JPopupMenugetComponentPopupMenu()
Returns JPopupMenu that assigned for this component.
Component[]getComponents()
Gets all the components in this container.
LocalegetDefaultLocale()
Returns the default locale used to initialize each JComponent's locale property upon creation.
FocusListener[]getFocusListeners()
Returns an array of all the focus listeners registered on this component.
SetgetFocusTraversalKeys(int id)
Returns the Set of focus traversal keys for a given traversal operation for this Container.
FontgetFont()
Gets the font of this component.
FontMetricsgetFontMetrics(Font font)
Gets the FontMetrics for the specified Font.
ColorgetForeground()
Gets the foreground color of this component.
GraphicsgetGraphics()
Returns this component's graphics context, which lets you draw on a component.
intgetHeight()
Returns the current height of this component.
HierarchyBoundsListener[]getHierarchyBoundsListeners()
Returns an array of all the hierarchy bounds listeners registered on this component.
HierarchyListener[]getHierarchyListeners()
Returns an array of all the hierarchy listeners registered on this component.
InputMapgetInputMap(int condition)
Returns the InputMap that is used during condition.
InputMapgetInputMap()
Returns the InputMap that is used when the component has focus.
InputMethodListener[]getInputMethodListeners()
Returns an array of all the input method listeners registered on this component.
InsetsgetInsets()
If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.
InsetsgetInsets(Insets insets)
Returns an Insets object containing this component's inset values.
KeyListener[]getKeyListeners()
Returns an array of all the key listeners registered on this component.
LayoutManagergetLayout()
Gets the layout manager for this container.
PointgetLocationOnScreen()
Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.
DimensiongetMaximumSize()
If the maximum size has been set to a non-null value just returns it.
DimensiongetMinimumSize()
If the minimum size has been set to a non-null value just returns it.
MouseListener[]getMouseListeners()
Returns an array of all the mouse listeners registered on this component.
MouseMotionListener[]getMouseMotionListeners()
Returns an array of all the mouse motion listeners registered on this component.
MouseWheelListener[]getMouseWheelListeners()
Returns an array of all the mouse wheel listeners registered on this component.
StringgetName()
Gets the name of the component.
ContainergetParent()
Gets the parent of this component.
DimensiongetPreferredSize()
If the preferredSize has been set to a non-null value just returns it.
PropertyChangeListener[]getPropertyChangeListeners()
Returns an array of all the property change listeners registered on this component.
JRootPanegetRootPane()
Returns the JRootPane ancestor for this component.
DimensiongetSize()
Returns the size of this component in the form of a Dimension object.
ToolkitgetToolkit()
Gets the toolkit of this component.
StringgetToolTipText(MouseEvent event)
Returns the string to be used as the tooltip for event.
StringgetToolTipText()
Returns the tooltip string that has been set with setToolTipText.
ContainergetTopLevelAncestor()
Returns the top-level ancestor of this component (either the containing Window or Applet), or null if this component has not been added to any container.
TransferHandlergetTransferHandler()
Gets the transferHandler property.
ObjectgetTreeLock()
Gets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations.
StringgetUIClassID()
Returns the UIDefaults key used to look up the name of the swing.plaf.ComponentUI class that defines the look and feel for this component.
VetoableChangeListener[]getVetoableChangeListeners()
Returns an array of all the vetoable change listeners registered on this component.
RectanglegetVisibleRect()
Returns the Component's "visible rectangle" - the intersection of this component's visible rectangle, new Rectangle(0, 0, getWidth(), getHeight()), and all of its ancestors' visible rectangles.
intgetWidth()
Returns the current width of this component.
booleanhasFocus()
Returns true if this Component is the focus owner.
voidinvalidate()
Invalidates the container.
booleanisEnabled()
Determines whether this component is enabled.
booleanisFocusable()
Returns whether this Component can be focused.
booleanisFocusOwner()
Returns true if this Component is the focus owner.
booleanisOpaque()
Returns true if this component is completely opaque.
booleanisRequestFocusEnabled()
Returns true if this JComponent should get focus; otherwise returns false.
booleanisShowing()
Determines whether this component is showing on screen.
booleanisVisible()
Determines whether this component should be visible when its parent is visible.
voidpaint(Graphics g)
Invoked by Swing to draw components.
voidpaintImmediately(Rectangle r)
Paints the specified region now.
voidpaintImmediately(int x, int y, int w, int h)
Paints the specified region in this component and all of its descendants that overlap the region, immediately.
voidprint(Graphics g)
Invoke this method to print the component to the specified Graphics.
voidputClientProperty(Object key, Object value)
Adds an arbitrary key/value "client property" to this component.
voidregisterKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition)
This method is now obsolete, please use a combination of getActionMap() and getInputMap() for similar behavior.
voidremove(int index)
Removes the component, specified by index , from this container.
voidremoveAll()
Removes all the components from this container.
voidremoveAncestorListener(AncestorListener listener)
Unregisters listener so that it will no longer receive AncestorEvents.
voidremoveComponentListener(ComponentListener l)
Removes the specified component listener so that it no longer receives component events from this component.
voidremoveFocusListener(FocusListener l)
Removes the specified focus listener so that it no longer receives focus events from this component.
voidremoveHierarchyBoundsListener(HierarchyBoundsListener l)
Removes the specified hierarchy bounds listener so that it no longer receives hierarchy bounds events from this component.
voidremoveHierarchyListener(HierarchyListener l)
Removes the specified hierarchy listener so that it no longer receives hierarchy changed events from this component.
voidremoveInputMethodListener(InputMethodListener l)
Removes the specified input method listener so that it no longer receives input method events from this component.
voidremoveKeyListener(KeyListener l)
Removes the specified key listener so that it no longer receives key events from this component.
voidremoveMouseListener(MouseListener l)
Removes the specified mouse listener so that it no longer receives mouse events from this component.
voidremoveMouseMotionListener(MouseMotionListener l)
Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component.
voidremoveMouseWheelListener(MouseWheelListener l)
Removes the specified mouse wheel listener so that it no longer receives mouse wheel events from this component.
voidremoveNotify()
Notifies this component that it no longer has a parent component.
voidremovePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list.
voidremoveVetoableChangeListener(VetoableChangeListener listener)
Removes a VetoableChangeListener from the listener list.
voidrepaint()
Repaints this component.
voidrequestFocus()
Requests that this Component gets the input focus.
booleanrequestFocusInWindow()
Requests that this Component gets the input focus.
voidrevalidate()
Supports deferred automatic layout.
voidscrollRectToVisible(Rectangle aRect)
Forwards the scrollRectToVisible() message to the JComponent's parent.
voidsetActionMap(ActionMap am)
Sets the ActionMap to am.
voidsetAlignmentX(float alignmentX)
Sets the horizontal alignment.
voidsetAlignmentY(float alignmentY)
Sets the vertical alignment.
voidsetBackground(Color bg)
Sets the background color of this component.
voidsetBorder(Border border)
Sets the border of this component.
voidsetBounds(Rectangle r)
Moves and resizes this component to conform to the new bounding rectangle r .
voidsetBounds(int x, int y, int width, int height)
Moves and resizes this component.
voidsetComponentOrientation(ComponentOrientation o)
Sets the language-sensitive orientation that is to be used to order the elements or text within this component.
voidsetComponentPopupMenu(JPopupMenu popup)
Sets the JPopupMenu for this JComponent.
voidsetCursor(Cursor cursor)
Sets the cursor image to the specified cursor.
voidsetDefaultLocale(Locale l)
Sets the default locale used to initialize each JComponent's locale property upon creation.
voidsetDoubleBuffered(boolean aFlag)
Sets whether this component should use a buffer to paint.
voidsetEnabled(boolean enabled)
Sets whether or not this component is enabled.
voidsetFocusable(boolean focusable)
Sets the focusable state of this Component to the specified value.
voidsetFocusTraversalKeys(int id, Set keystrokes)
Sets the focus traversal keys for a given traversal operation for this Component.
voidsetFont(Font font)
Sets the font for this component.
voidsetForeground(Color fg)
Sets the foreground color of this component.
voidsetInputMap(int condition, InputMap map)
Sets the InputMap to use under the condition condition to map.
voidsetInputVerifier(InputVerifier inputVerifier)
Sets the input verifier for this component.
voidsetLayout(LayoutManager mgr)
Sets the layout manager for this container.
voidsetLocation(int x, int y)
Moves this component to a new location.
voidsetMaximumSize(Dimension maximumSize)
Sets the maximum size of this component to a constant value.
voidsetMinimumSize(Dimension minimumSize)
Sets the minimum size of this component to a constant value.
voidsetName(String name)
Sets the name of the component to the specified string.
voidsetOpaque(boolean isOpaque)
If true the component paints every pixel within its bounds.
voidsetPreferredSize(Dimension preferredSize)
Sets the preferred size of this component.
voidsetRequestFocusEnabled(boolean requestFocusEnabled)
Provides a hint as to whether or not this JComponent should get focus.
voidsetSize(Dimension d)
Resizes this component so that it has width d.width and height d.height .
voidsetSize(int width, int height)
Resizes this component so that it has width width and height height .
voidsetToolTipText(String text)
Registers the text to display in a tool tip.
voidsetTransferHandler(TransferHandler newHandler)
Sets the TransferHandler , which provides support for transfer of data into and out of this component via cut/copy/paste and drag and drop.
voidsetVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget)
Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus.
voidsetVisible(boolean aFlag)
Makes the component visible or invisible.
StringtoString()
Returns a string representation of this component and its values.
voidupdateUI()
Resets the UI property to a value from the current look and feel.
voidvalidate()
Validates this container and all of its subcomponents.