javax.swing
public abstract class JComponent extends Container implements Serializable
Modifier and Type | Class and Description |
---|---|
class |
JComponent.AccessibleJComponent
Basic accessibility support for
JComponent derived
widgets. |
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected AccessibleContext |
accessibleContext
The accessible context of this
JComponent . |
protected EventListenerList |
listenerList
Listeners for events other than
PropertyChangeEvent are
handled by this listener list. |
static String |
TOOL_TIP_TEXT_KEY |
protected ComponentUI |
ui
The user interface delegate for this component.
|
static int |
UNDEFINED_CONDITION
Constant used to indicate that no condition has been assigned to a
particular action.
|
static int |
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
Constant used to indicate that an action should be performed only when
the component is an ancestor of the component which has focus.
|
static int |
WHEN_FOCUSED
Constant used to indicate that an action should be performed only when
the component has focus.
|
static int |
WHEN_IN_FOCUSED_WINDOW
Constant used to indicate that an action should be performed only when
the component is in the window which has focus.
|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JComponent()
Creates a new
JComponent instance. |
Modifier and Type | Method and Description |
---|---|
void |
addAncestorListener(AncestorListener listener)
Register an
AncestorListener . |
void |
addNotify()
Receives notification if this component is added to a parent component.
|
void |
addVetoableChangeListener(VetoableChangeListener listener)
Register a
VetoableChangeListener . |
void |
computeVisibleRect(Rectangle rect)
Compute the component's visible rectangle, which is defined
recursively as either the component's bounds, if it has no parent, or
the intersection of the component's bounds with the visible rectangle
of its parent.
|
boolean |
contains(int x,
int y)
Returns
true if the coordinates (x, y) lie within
the bounds of this component and false otherwise. |
JToolTip |
createToolTip()
Return the
toolTip property of this component, creating it and
setting it if it is currently null . |
void |
disable()
Deprecated.
replaced by
setEnabled(boolean) |
void |
enable()
Deprecated.
replaced by
setEnabled(boolean) |
void |
firePropertyChange(String property,
boolean oldValue,
boolean newValue)
Fires a property change for a primitive boolean property.
|
void |
firePropertyChange(String property,
int oldValue,
int newValue)
Fires a property change for a primitive integer property.
|
protected void |
fireVetoableChange(String propertyName,
Object oldValue,
Object newValue)
Call
VetoableChangeListener.vetoableChange(java.beans.PropertyChangeEvent) on all listeners
registered to listen to a given property. |
AccessibleContext |
getAccessibleContext()
Get the value of the accessibleContext property for this component.
|
ActionListener |
getActionForKeyStroke(KeyStroke ks)
Get the ActionListener (typically an
Action object) which is
associated with a particular keystroke. |
ActionMap |
getActionMap() |
float |
getAlignmentX()
Get the value of the
alignmentX property. |
float |
getAlignmentY()
Get the value of the
alignmentY property. |
AncestorListener[] |
getAncestorListeners()
Return all registered
AncestorListener objects. |
boolean |
getAutoscrolls()
Get the current value of the
autoscrolls property. |
Border |
getBorder()
Get the value of the
border property. |
Rectangle |
getBounds(Rectangle rv)
Get the component's current bounding box.
|
Object |
getClientProperty(Object key)
Get a client property associated with this component and a particular
key.
|
protected Graphics |
getComponentGraphics(Graphics g)
Prepares a graphics context for painting this object.
|
JPopupMenu |
getComponentPopupMenu()
Returns the popup menu for this component.
|
int |
getConditionForKeyStroke(KeyStroke ks)
Return the condition that determines whether a registered action
occurs in response to the specified keystroke.
|
int |
getDebugGraphicsOptions()
Get the value of the
debugGraphicsOptions property. |
static Locale |
getDefaultLocale()
Returns the locale used as the default for all new components.
|
Graphics |
getGraphics()
Returns the Graphics context for this component.
|
int |
getHeight()
Returns the height of this component.
|
boolean |
getInheritsPopupMenu()
Returns the flag that controls whether or not the component inherits its
parent's popup menu when no popup menu is specified for this component.
|
InputMap |
getInputMap()
Returns the input map associated with this component for the
WHEN_FOCUSED state. |
InputMap |
getInputMap(int condition)
Returns the input map associated with this component for the given
state/condition.
|
InputVerifier |
getInputVerifier()
Returns the currently set input verifier for this component.
|
Insets |
getInsets()
Get the component's insets, which are calculated from
the
border property. |
Insets |
getInsets(Insets insets)
Get the component's insets, which are calculated from the
border property. |
<T extends EventListener> |
getListeners(Class<T> listenerType)
Returns all registered
EventListener s of the given
listenerType . |
Point |
getLocation(Point rv)
Get the component's location.
|
Dimension |
getMaximumSize()
Get the component's maximum size.
|
Dimension |
getMinimumSize()
Get the component's minimum size.
|
Component |
getNextFocusableComponent()
Deprecated.
|
Dimension |
getPreferredSize()
Get the component's preferred size.
|
KeyStroke[] |
getRegisteredKeyStrokes()
Return the set of
KeyStroke objects which are registered
to initiate actions on this component. |
JRootPane |
getRootPane()
Returns the first ancestor of this component which is a
JRootPane . |
Dimension |
getSize(Dimension rv)
Get the component's size.
|
Point |
getToolTipLocation(MouseEvent event)
Return the location at which the
toolTipText property should
be displayed, when triggered by a particular mouse event. |
String |
getToolTipText()
Returns the current tooltip text for this component, or
null
if none has been set. |
String |
getToolTipText(MouseEvent event)
Returns the tooltip text for this component for a particular mouse
event.
|
Container |
getTopLevelAncestor()
|
TransferHandler |
getTransferHandler()
Get the value of the
transferHandler property. |
String |
getUIClassID()
Get the value of the UIClassID property.
|
boolean |
getVerifyInputWhenFocusTarget() |
VetoableChangeListener[] |
getVetoableChangeListeners()
Return all registered
VetoableChangeListener objects. |
Rectangle |
getVisibleRect()
Return the component's visible rectangle in a new
Rectangle ,
rather than via a return slot. |
int |
getWidth()
Returns the width of this component.
|
int |
getX()
Returns the X coordinate of the upper left corner of this component.
|
int |
getY()
Returns the Y coordinate of the upper left corner of this component.
|
void |
grabFocus()
Requests that this component receive input focus, giving window
focus to the top level ancestor of this component.
|
boolean |
isDoubleBuffered()
Get the value of the
doubleBuffered property. |
static boolean |
isLightweightComponent(Component c)
Return
true if the provided component has no native peer;
in other words, if it is a "lightweight component". |
boolean |
isManagingFocus()
Deprecated.
1.4 Use
Component.setFocusTraversalKeys(int, Set) and
Container.setFocusCycleRoot(boolean) instead |
boolean |
isOpaque()
Return the current value of the
opaque property. |
boolean |
isOptimizedDrawingEnabled()
Return
true if the component can guarantee that none of its
children will overlap in Z-order. |
boolean |
isPaintingTile()
Return
true if this component is currently painting a tile,
this means that paint() is called again on another child component. |
boolean |
isRequestFocusEnabled()
Get the value of the
requestFocusEnabled property. |
boolean |
isValidateRoot()
Return
true if this component is a validation root; this
will cause calls to Container.invalidate() in this component's children
to be "captured" at this component, and not propagate to its parents. |
void |
paint(Graphics g)
Paint the component.
|
protected void |
paintBorder(Graphics g)
Paint the component's border.
|
protected void |
paintChildren(Graphics g)
Paint the component's children.
|
protected void |
paintComponent(Graphics g)
Paint the component's body.
|
void |
paintImmediately(int x,
int y,
int w,
int h)
A variant of
paintImmediately(Rectangle) which takes
integer parameters. |
void |
paintImmediately(Rectangle r)
Transform the provided dirty rectangle for this component into the
appropriate ancestral
JRootPane and call paint(java.awt.Graphics) on
that root pane. |
protected String |
paramString()
Return a string representation for this component, for use in
debugging.
|
void |
print(Graphics g)
Prints this component to the given Graphics context.
|
void |
printAll(Graphics g)
Prints this component to the given Graphics context.
|
protected void |
printBorder(Graphics g)
Print this component's border to the specified Graphics context.
|
protected void |
printChildren(Graphics g)
Print this component's children to the specified Graphics context.
|
protected void |
printComponent(Graphics g)
Prints this component to the specified Graphics context.
|
protected void |
processComponentKeyEvent(KeyEvent e)
A hook for subclasses which want to customize event processing.
|
protected boolean |
processKeyBinding(KeyStroke ks,
KeyEvent e,
int condition,
boolean pressed) |
protected void |
processKeyEvent(KeyEvent e)
|
protected void |
processMouseMotionEvent(MouseEvent ev)
Processes mouse motion event, like dragging and moving.
|
void |
putClientProperty(Object key,
Object value)
Add a client property
value to this component, associated
with key . |
void |
registerKeyboardAction(ActionListener act,
KeyStroke stroke,
int cond)
A variant of
registerKeyboardAction(ActionListener,String,KeyStroke,int) which
provides null for the command name. |
void |
registerKeyboardAction(ActionListener act,
String cmd,
KeyStroke stroke,
int cond)
An obsolete method to register a keyboard action on this component.
|
void |
removeAncestorListener(AncestorListener listener)
Unregister an
AncestorListener . |
void |
removeNotify()
Receives notification that this component no longer has a parent.
|
void |
removeVetoableChangeListener(VetoableChangeListener listener)
Unregister a
VetoableChangeChangeListener . |
void |
repaint(long tm,
int x,
int y,
int width,
int height)
Mark the described region of this component as dirty in the current
RepaintManager . |
void |
repaint(Rectangle r)
Mark the described region of this component as dirty in the current
RepaintManager . |
boolean |
requestDefaultFocus()
Deprecated.
Use
requestFocus() on the default component provided
from the FocusTraversalPolicy instead. |
void |
requestFocus()
Requests that this component gets the input focus if the
requestFocusEnabled property is set to
true . |
boolean |
requestFocus(boolean temporary)
This method is overridden to make it public so that it can be used
by look and feel implementations.
|
boolean |
requestFocusInWindow()
Requests that this component gets the input focus if the top level
window that contains this component has the focus and the
requestFocusEnabled property is set to
true . |
protected boolean |
requestFocusInWindow(boolean temporary)
This method is overridden to make it public so that it can be used
by look and feel implementations.
|
void |
resetKeyboardActions()
Reset all keyboard action registries.
|
void |
reshape(int x,
int y,
int w,
int h)
Moves and resizes the component.
|
void |
revalidate()
Queue a an invalidation and revalidation of this component, using
RepaintManager.addInvalidComponent(javax.swing.JComponent) . |
void |
scrollRectToVisible(Rectangle r)
Calls
scrollRectToVisible on the component's parent. |
void |
setActionMap(ActionMap map) |
void |
setAlignmentX(float a)
Set the value of the
alignmentX property. |
void |
setAlignmentY(float a)
Set the value of the
alignmentY property. |
void |
setAutoscrolls(boolean a)
Set the value of the
autoscrolls property. |
void |
setBackground(Color bg)
Set the value of the
background property. |
void |
setBorder(Border newBorder)
Set the value of the
border property. |
void |
setComponentPopupMenu(JPopupMenu popup)
Sets the popup menu for this component (this is a bound property with
the property name 'componentPopupMenu').
|
void |
setDebugGraphicsOptions(int debugOptions)
Set the value of the
debugGraphicsOptions property. |
static void |
setDefaultLocale(Locale l)
Sets the locale to be used as the default for all new components.
|
void |
setDoubleBuffered(boolean db)
Set the value of the
doubleBuffered property. |
void |
setEnabled(boolean enable)
Set the value of the
enabled property. |
void |
setFont(Font f)
Set the value of the
font property. |
void |
setForeground(Color fg)
Set the value of the
foreground property. |
void |
setInheritsPopupMenu(boolean inherit)
Sets the flag that controls whether or not the component inherits its
parent's popup menu when no popup menu is specified for this component.
|
void |
setInputMap(int condition,
InputMap map)
Sets the input map for the given condition.
|
void |
setInputVerifier(InputVerifier verifier)
Sets the input verifier to use by this component.
|
void |
setNextFocusableComponent(Component aComponent)
Deprecated.
Use FocusTraversalPolicy instead
|
void |
setOpaque(boolean isOpaque)
Set if the component should paint all pixels withing its bounds.
|
void |
setRequestFocusEnabled(boolean e)
Set the value of the
requestFocusEnabled property. |
void |
setToolTipText(String text)
Set the tooltip text for this component.
|
void |
setTransferHandler(TransferHandler newHandler)
Set the value of the
transferHandler property. |
protected void |
setUI(ComponentUI newUI)
Install a new UI delegate as the component's
ui property. |
void |
setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget) |
void |
setVisible(boolean v)
Set the value of the visible property.
|
void |
unregisterKeyboardAction(KeyStroke aKeyStroke)
Remove a keyboard action registry.
|
void |
update(Graphics g)
Call
paint(java.awt.Graphics) . |
void |
updateUI()
This method should be overridden in subclasses.
|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected AccessibleContext accessibleContext
JComponent
.protected ComponentUI ui
protected EventListenerList listenerList
PropertyChangeEvent
are
handled by this listener list. PropertyChangeEvents are handled in
Component.changeSupport
.public static final String TOOL_TIP_TEXT_KEY
public static final int UNDEFINED_CONDITION
public static final int WHEN_FOCUSED
public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
public static final int WHEN_IN_FOCUSED_WINDOW
public JComponent()
JComponent
instance.public final Object getClientProperty(Object key)
key
- The key with which to look up the client propertyclientProperties
,
getClientProperties()
,
putClientProperty(java.lang.Object, java.lang.Object)
public final void putClientProperty(Object key, Object value)
value
to this component, associated
with key
. If there is an existing client property
associated with key
, it will be replaced. A
PropertyChangeEvent
is sent to registered listeners (with the
name of the property being key.toString()
).key
- The key of the client property association to addvalue
- The value of the client property association to addclientProperties
,
getClientProperties()
,
getClientProperty(java.lang.Object)
public void removeAncestorListener(AncestorListener listener)
AncestorListener
.listener
- The listener to unregisteraddAncestorListener(javax.swing.event.AncestorListener)
public void removeVetoableChangeListener(VetoableChangeListener listener)
VetoableChangeChangeListener
.listener
- The listener to unregisteraddVetoableChangeListener(java.beans.VetoableChangeListener)
public void addAncestorListener(AncestorListener listener)
AncestorListener
.listener
- The listener to registerremoveVetoableChangeListener(java.beans.VetoableChangeListener)
public void addVetoableChangeListener(VetoableChangeListener listener)
VetoableChangeListener
.listener
- The listener to registerremoveVetoableChangeListener(java.beans.VetoableChangeListener)
,
listenerList
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
EventListener
s of the given
listenerType
.getListeners
in class Container
listenerType
- the class of listeners to filter (null
not permitted).ClassCastException
- if listenerType
does not implement
the EventListener
interface.NullPointerException
- if listenerType
is
null
.getAncestorListeners()
,
listenerList
public AncestorListener[] getAncestorListeners()
AncestorListener
objects.AncestorListener
objects in listenerList
public VetoableChangeListener[] getVetoableChangeListeners()
VetoableChangeListener
objects.VetoableChangeListener
objects
registered with this component (possibly empty but never
null
).protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException
VetoableChangeListener.vetoableChange(java.beans.PropertyChangeEvent)
on all listeners
registered to listen to a given property. Any method which changes
the specified property of this component should call this method.propertyName
- The property which changedoldValue
- The old value of the propertynewValue
- The new value of the propertyPropertyVetoException
- if the change was vetoed by a listeneraddVetoableChangeListener(java.beans.VetoableChangeListener)
,
removeVetoableChangeListener(java.beans.VetoableChangeListener)
public void firePropertyChange(String property, int oldValue, int newValue)
firePropertyChange
in class Component
property
- the name of the propertyoldValue
- the old value of the propertynewValue
- the new value of the propertypublic void firePropertyChange(String property, boolean oldValue, boolean newValue)
firePropertyChange
in class Component
property
- the name of the propertyoldValue
- the old value of the propertynewValue
- the new value of the propertypublic AccessibleContext getAccessibleContext()
getAccessibleContext
in class Component
public float getAlignmentX()
alignmentX
property.getAlignmentX
in class Container
setAlignmentX(float)
,
alignmentY
public float getAlignmentY()
alignmentY
property.getAlignmentY
in class Container
setAlignmentY(float)
,
alignmentX
public boolean getAutoscrolls()
autoscrolls
property.public void setBorder(Border newBorder)
border
property.newBorder
- The new value of the propertygetBorder()
public Border getBorder()
border
property.setBorder(javax.swing.border.Border)
public Rectangle getBounds(Rectangle rv)
null
is provided) return a new Rectangle
.protected Graphics getComponentGraphics(Graphics g)
debugGraphicsOptions
is not equal to DebugGraphics.NONE_OPTION
, produce a new DebugGraphics
object
wrapping the parameter. Otherwise configure the parameter with this
component's foreground color and font.g
- The graphics context to wrap or configuredebugGraphicsOptions
,
paint(java.awt.Graphics)
public int getDebugGraphicsOptions()
debugGraphicsOptions
property.setDebugGraphicsOptions(int)
,
debugGraphicsOptions
public Insets getInsets()
border
property. If the border is null
,
calls Container.getInsets()
.public Insets getInsets(Insets insets)
border
property. If the border is null
, calls Container.getInsets()
. The passed-in Insets
value will be
used as the return value, if possible.insets
- Return value object to reuse, if possiblepublic Point getLocation(Point rv)
Point
value
will be used as the return value, if possible.getLocation
in class Component
rv
- Return value object to reuse, if possiblepublic Dimension getMaximumSize()
maximumSize
property
has been explicitly set, it is returned. If the maximumSize
property has not been set but the ui
property has been, the
result of ComponentUI.getMaximumSize(javax.swing.JComponent)
is returned. If neither
property has been set, the result of Container.getMaximumSize()
is returned.getMaximumSize
in class Container
Component.setMaximumSize(java.awt.Dimension)
,
Component.getMaximumSize()
,
Component.isMaximumSizeSet()
,
ComponentUI.getMaximumSize(JComponent)
public Dimension getMinimumSize()
minimumSize
property
has been explicitly set, it is returned. If the minimumSize
property has not been set but the ui
property has been, the
result of ComponentUI.getMinimumSize(javax.swing.JComponent)
is returned. If neither
property has been set, the result of Container.getMinimumSize()
is returned.getMinimumSize
in class Container
Component.setMinimumSize(java.awt.Dimension)
,
Component.getMinimumSize()
,
Component.isMinimumSizeSet()
,
ComponentUI.getMinimumSize(JComponent)
public Dimension getPreferredSize()
preferredSize
property has been explicitly set, it is returned. If the
preferredSize
property has not been set but the ui
property has been, the result of ComponentUI.getPreferredSize(javax.swing.JComponent)
is
returned. If neither property has been set, the result of Container.getPreferredSize()
is returned.getPreferredSize
in class Container
Component.setPreferredSize(java.awt.Dimension)
,
Component.getPreferredSize()
,
Component.isPreferredSizeSet()
,
ComponentUI.getPreferredSize(JComponent)
public Component getNextFocusableComponent()
FocusTraversalPolicy
nextFocusableComponent
property.null
if none has been set.public KeyStroke[] getRegisteredKeyStrokes()
KeyStroke
objects which are registered
to initiate actions on this component.null
).public JRootPane getRootPane()
JRootPane
.
Equivalent to calling SwingUtilities.getRootPane(this);
.null
if none exists.public Dimension getSize(Dimension rv)
Dimension
value
will be used as the return value, if possible.public JToolTip createToolTip()
toolTip
property of this component, creating it and
setting it if it is currently null
. This method can be
overridden in subclasses which wish to control the exact form of
tooltip created.public Point getToolTipLocation(MouseEvent event)
toolTipText
property should
be displayed, when triggered by a particular mouse event.event
- The event the tooltip is being presented in response tonull
if swing is to choose a default location.public void setToolTipText(String text)
null
value is set, this component is registered in the
ToolTipManager
in order to turn on tooltips for this
component. If a null
value is set, tooltips are turne off
for this component.text
- the tooltip text for this componentgetToolTipText()
,
getToolTipText(MouseEvent)
public String getToolTipText()
null
if none has been set.null
if none has been setsetToolTipText(java.lang.String)
,
getToolTipText(MouseEvent)
public String getToolTipText(MouseEvent event)
getToolTipText()
.event
- the mouse event which triggered the tooltipsetToolTipText(java.lang.String)
,
getToolTipText()
public boolean getInheritsPopupMenu()
setInheritsPopupMenu(boolean)
public void setInheritsPopupMenu(boolean inherit)
inherit
- the new flag value.getInheritsPopupMenu()
public JPopupMenu getComponentPopupMenu()
null
AND the getInheritsPopupMenu()
method returns
true
, this method will return the parent's popup menu (if it
has one).null
.setComponentPopupMenu(JPopupMenu)
,
getInheritsPopupMenu()
public void setComponentPopupMenu(JPopupMenu popup)
popup
- the popup menu (null
permitted).getComponentPopupMenu()
public Container getTopLevelAncestor()
Window
or Applet
) which this component is
contained within, or null
if no ancestors exist.public void computeVisibleRect(Rectangle rect)
rect
- The return value slot to place the visible rectangle inpublic Rectangle getVisibleRect()
Rectangle
,
rather than via a return slot.computeVisibleRect(Rectangle)
public void grabFocus()
Requests that this component receive input focus, giving window focus to the top level ancestor of this component. Only works on displayable, focusable, visible components.
This method should not be called by clients; it is intended for
focus implementations. Use Component.AccessibleAWTComponent.requestFocus()
instead.
public boolean isDoubleBuffered()
doubleBuffered
property.isDoubleBuffered
in class Component
public static boolean isLightweightComponent(Component c)
true
if the provided component has no native peer;
in other words, if it is a "lightweight component".c
- The component to test for lightweight-nesspublic boolean isManagingFocus()
Component.setFocusTraversalKeys(int, Set)
and
Container.setFocusCycleRoot(boolean)
insteadtrue
if you wish this component to manage its own
focus. In particular: if you want this component to be sent
TAB
and SHIFT+TAB
key events, and to not
have its children considered as focus transfer targets. If
true
, focus traversal around this component changes to
CTRL+TAB
and CTRL+SHIFT+TAB
.true
if you want this component to manage its own
focus, otherwise (by default) false
public boolean isOpaque()
opaque
property.isOpaque
in class Component
Component.isLightweight()
public boolean isOptimizedDrawingEnabled()
true
if the component can guarantee that none of its
children will overlap in Z-order. This is a hint to the painting system.
The default is to return true
, but some components such as
JLayeredPane
should override this to return false
.public boolean isPaintingTile()
true
if this component is currently painting a tile,
this means that paint() is called again on another child component. This
method returns false
if this component does not paint a tile
or if the last tile is currently painted.public boolean isRequestFocusEnabled()
requestFocusEnabled
property.public boolean isValidateRoot()
true
if this component is a validation root; this
will cause calls to Container.invalidate()
in this component's children
to be "captured" at this component, and not propagate to its parents.
For most components this should return false
, but some
components such as JViewport
will want to return
true
.public void paint(Graphics g)
Paint the component. This is a delicate process, and should only be
called from the repaint thread, under control of the RepaintManager
. Client code should usually call Component.repaint()
to
trigger painting.
The body of the paint
call involves calling paintComponent(java.awt.Graphics)
, paintBorder(java.awt.Graphics)
, and paintChildren(java.awt.Graphics)
in
order. If you want to customize painting behavior, you should override
one of these methods rather than paint
.
For more details on the painting sequence, see this article.
paint
in class Container
g
- The graphics context to paint withpaintImmediately(Rectangle)
protected void paintBorder(Graphics g)
Border.paintBorder(java.awt.Component, java.awt.Graphics, int, int, int, int)
on the border
property, if it is
non-null
. You may override this if you wish to customize
border painting behavior. The border is painted after the component's
body, but before the component's children.g
- The graphics context with which to paint the borderpaint(java.awt.Graphics)
,
paintChildren(java.awt.Graphics)
,
paintComponent(java.awt.Graphics)
protected void paintChildren(Graphics g)
Container.paint(java.awt.Graphics)
, which recursively calls paint(java.awt.Graphics)
on any of the
component's children, with appropriate changes to coordinate space and
clipping region. You may override this if you wish to customize
children painting behavior. The children are painted after the
component's body and border.g
- The graphics context with which to paint the childrenpaint(java.awt.Graphics)
,
paintBorder(java.awt.Graphics)
,
paintComponent(java.awt.Graphics)
protected void paintComponent(Graphics g)
ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)
on the ui
property of the component, if
it is non-null
. You may override this if you wish to
customize the component's body-painting behavior. The component's body
is painted first, before the border and children.g
- The graphics context with which to paint the bodypaint(java.awt.Graphics)
,
paintBorder(java.awt.Graphics)
,
paintChildren(java.awt.Graphics)
public void paintImmediately(int x, int y, int w, int h)
paintImmediately(Rectangle)
which takes
integer parameters.x
- The left x coordinate of the dirty regiony
- The top y coordinate of the dirty regionw
- The width of the dirty regionh
- The height of the dirty regionpublic void paintImmediately(Rectangle r)
JRootPane
and call paint(java.awt.Graphics)
on
that root pane. This method is called from the RepaintManager
and should always be called within the painting thread.
This method will acquire a double buffer from the RepaintManager
if the component's doubleBuffered
property is
true
and the paint
call is the
first recursive paint
call inside swing.
The method will also modify the provided Graphics
context
via the getComponentGraphics(java.awt.Graphics)
method. If you want to customize
the graphics object used for painting, you should override that method
rather than paint
.
r
- The dirty rectangle to paintprotected String paramString()
paramString
in class Container
public void registerKeyboardAction(ActionListener act, KeyStroke stroke, int cond)
registerKeyboardAction(ActionListener,String,KeyStroke,int)
which
provides null
for the command name.act
- the action listener to notify when the keystroke occurs.stroke
- the key stroke.cond
- the condition (one of WHEN_FOCUSED
,
WHEN_IN_FOCUSED_WINDOW
and
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
).public void registerKeyboardAction(ActionListener act, String cmd, KeyStroke stroke, int cond)
getInputMap
and getActionMap
to fetch mapping tables from keystrokes to commands, and commands to
actions, respectively, and modify those mappings directly.act
- The action to be registeredcmd
- The command to deliver in the delivered ActionEvent
stroke
- The keystroke to register oncond
- One of the values UNDEFINED_CONDITION
,
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
, WHEN_FOCUSED
, or
WHEN_IN_FOCUSED_WINDOW
, indicating the condition which must
be met for the action to be firedunregisterKeyboardAction(javax.swing.KeyStroke)
,
getConditionForKeyStroke(javax.swing.KeyStroke)
,
resetKeyboardActions()
public final void setInputMap(int condition, InputMap map)
condition
- the condition (one of WHEN_FOCUSED
,
WHEN_IN_FOCUSED_WINDOW
and
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
).map
- the map.IllegalArgumentException
- if condition
is not one of
the specified values.public final InputMap getInputMap(int condition)
condition
- the state (one of WHEN_FOCUSED
,
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
and
WHEN_IN_FOCUSED_WINDOW
).IllegalArgumentException
- if condition
is not one of
the specified values.public final InputMap getInputMap()
WHEN_FOCUSED
state.getInputMap(int)
public final ActionMap getActionMap()
public final void setActionMap(ActionMap map)
public int getConditionForKeyStroke(KeyStroke ks)
ks
- The keystroke to return the condition ofUNDEFINED_CONDITION
, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
, WHEN_FOCUSED
, or WHEN_IN_FOCUSED_WINDOW
registerKeyboardAction(ActionListener, KeyStroke, int)
,
unregisterKeyboardAction(javax.swing.KeyStroke)
,
resetKeyboardActions()
public ActionListener getActionForKeyStroke(KeyStroke ks)
Action
object) which is
associated with a particular keystroke.ks
- The keystroke to retrieve the action ofprotected void processComponentKeyEvent(KeyEvent e)
protected void processKeyEvent(KeyEvent e)
InputMap
/ ActionMap
system.
See
this report for more details, it's somewhat complex.processKeyEvent
in class Component
e
- the KeyEvent
to processKeyListener
,
Component.addKeyListener(KeyListener)
,
Component.enableEvents(long)
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
public void unregisterKeyboardAction(KeyStroke aKeyStroke)
aKeyStroke
- The keystroke to unregisterregisterKeyboardAction(ActionListener, KeyStroke, int)
,
getConditionForKeyStroke(javax.swing.KeyStroke)
,
resetKeyboardActions()
public void resetKeyboardActions()
public void repaint(long tm, int x, int y, int width, int height)
RepaintManager
. This will queue an asynchronous repaint using
the system painting thread in the near future.repaint
in class Component
tm
- ignoredx
- coordinate of the region to mark as dirtyy
- coordinate of the region to mark as dirtywidth
- dimension of the region to mark as dirtyheight
- dimension of the region to mark as dirtyComponent.update(Graphics)
public void repaint(Rectangle r)
RepaintManager
. This will queue an asynchronous repaint using
the system painting thread in the near future.r
- The rectangle to mark as dirtypublic boolean requestDefaultFocus()
requestFocus()
on the default component provided
from the FocusTraversalPolicy
instead.FocusTraversalPolicy
.requestFocus()
public void revalidate()
RepaintManager.addInvalidComponent(javax.swing.JComponent)
.public void scrollRectToVisible(Rectangle r)
scrollRectToVisible
on the component's parent.
Components which can service this call should override.r
- The rectangle to make visiblepublic void setAlignmentX(float a)
alignmentX
property.a
- The new value of the propertypublic void setAlignmentY(float a)
alignmentY
property.a
- The new value of the propertypublic void setAutoscrolls(boolean a)
autoscrolls
property.a
- The new value of the propertypublic void setDebugGraphicsOptions(int debugOptions)
debugGraphicsOptions
property.debugOptions
- The new value of the propertypublic void setDoubleBuffered(boolean db)
doubleBuffered
property.db
- The new value of the propertypublic void setEnabled(boolean enable)
enabled
property.setEnabled
in class Component
enable
- The new value of the propertyComponent.isEnabled()
,
Component.isLightweight()
public void setFont(Font f)
font
property.setFont
in class Container
f
- The new value of the propertyComponent.getFont()
public void setBackground(Color bg)
background
property.setBackground
in class Component
bg
- The new value of the propertyComponent.getBackground()
public void setForeground(Color fg)
foreground
property.setForeground
in class Component
fg
- The new value of the propertyComponent.getForeground()
public void setNextFocusableComponent(Component aComponent)
FocusTraversalPolicy
for
this component.aComponent
- The component to set as the next focusablepublic void setRequestFocusEnabled(boolean e)
requestFocusEnabled
property.e
- The new value of the propertypublic TransferHandler getTransferHandler()
transferHandler
property.setTransferHandler(javax.swing.TransferHandler)
public void setTransferHandler(TransferHandler newHandler)
transferHandler
property.newHandler
- The new value of the propertygetTransferHandler()
public void setOpaque(boolean isOpaque)
isOpaque
- if true, paint all pixels. If false, expect the clean
background.ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)
public void setVisible(boolean v)
setVisible
in class Component
v
- The new value of the propertyComponent.isVisible()
public void update(Graphics g)
paint(java.awt.Graphics)
.update
in class Container
g
- The graphics context to paint intoComponent.paint(Graphics)
,
Component.repaint()
public String getUIClassID()
UIDefaults
table managed by UIManager
, the
value of which is the name of a class to load for the component's
ui
property."ComponentUI"
setUI(javax.swing.plaf.ComponentUI)
,
updateUI()
protected void setUI(ComponentUI newUI)
ui
property. In
the process, this will call ComponentUI.uninstallUI(javax.swing.JComponent)
on any
existing value for the ui
property, and ComponentUI.installUI(javax.swing.JComponent)
on the new UI delegate.newUI
- The new UI delegate to installupdateUI()
,
getUIClassID()
public void updateUI()
getUIClassID()
) from the UIManager
, and calls setUI(javax.swing.plaf.ComponentUI)
with the new delegate.public static Locale getDefaultLocale()
Locale.getDefault()
(that is, the platform
default locale).null
).setDefaultLocale(Locale)
public static void setDefaultLocale(Locale l)
null
, the getDefaultLocale()
method will
return the platform default locale.l
- the locale (null
permitted).public InputVerifier getInputVerifier()
null
if nonepublic void setInputVerifier(InputVerifier verifier)
verifier
- the input verifier, or null
public boolean getVerifyInputWhenFocusTarget()
public void setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget)
public void requestFocus()
true
.
This also means that this component's top-level window becomes
the focused window, if that is not already the case.
The preconditions that have to be met to become a focus owner is that
the component must be displayable, visible and focusable.
Note that this signals only a request for becoming focused. There are
situations in which it is not possible to get the focus. So developers
should not assume that the component has the focus until it receives
a FocusEvent
with a value of
FocusEvent.FOCUS_GAINED
.requestFocus
in class Component
Component.AccessibleAWTComponent.requestFocus()
public boolean requestFocus(boolean temporary)
requestFocus()
or
requestFocusInWindow()
instead.requestFocus
in class Component
temporary
- if the focus change is temporaryfalse
if the focus change request will definitly
fail, true
if it will likely succeedComponent.requestFocus(boolean)
public boolean requestFocusInWindow()
true
.
The preconditions that have to be met to become a focus owner is that
the component must be displayable, visible and focusable.
Note that this signals only a request for becoming focused. There are
situations in which it is not possible to get the focus. So developers
should not assume that the component has the focus until it receives
a FocusEvent
with a value of
FocusEvent.FOCUS_GAINED
.requestFocusInWindow
in class Component
false
if the focus change request will definitly
fail, true
if it will likely succeedComponent.requestFocusInWindow()
protected boolean requestFocusInWindow(boolean temporary)
requestFocus()
or
requestFocusInWindow()
instead.requestFocusInWindow
in class Component
temporary
- if the focus change is temporaryfalse
if the focus change request will definitly
fail, true
if it will likely succeedComponent.requestFocus(boolean)
public void addNotify()
addNotify
in class Container
Component.isDisplayable()
,
Component.removeNotify()
public void removeNotify()
Component.getParent()
.removeNotify
in class Container
Component.isDisplayable()
,
Component.addNotify()
public boolean contains(int x, int y)
true
if the coordinates (x, y) lie within
the bounds of this component and false
otherwise.
x and y are relative to the coordinate space of the component.contains
in class Component
x
- the X coordinate of the point to checky
- the Y coordinate of the point to checktrue
if the specified point lies within the bounds
of this component, false
otherwiseComponent.getComponentAt(int, int)
public void disable()
setEnabled(boolean)
public void enable()
setEnabled(boolean)
public Graphics getGraphics()
getGraphics
in class Component
Component.paint(Graphics)
public int getX()
getBounds(java.awt.Rectangle)
or getLocation(java.awt.Point)
because it does not cause any heap allocation.public int getY()
getBounds(java.awt.Rectangle)
or getLocation(java.awt.Point)
because it does not cause any heap allocation.public int getHeight()
getBounds(java.awt.Rectangle)
or getSize(java.awt.Dimension)
because it does not cause
any heap allocation.public int getWidth()
getBounds(java.awt.Rectangle)
or getSize(java.awt.Dimension)
because it does not cause
any heap allocation.public void print(Graphics g)
printComponent(java.awt.Graphics)
,
printBorder(java.awt.Graphics)
and printChildren(java.awt.Graphics)
in this order.
Double buffering is temporarily turned off so the painting goes directly
to the supplied Graphics context.print
in class Container
g
- the Graphics context to print ontoComponent.paint(Graphics)
public void printAll(Graphics g)
print(java.awt.Graphics)
.printAll
in class Component
g
- the Graphics context to print ontoComponent.paintAll(Graphics)
protected void printComponent(Graphics g)
paintComponent(java.awt.Graphics)
. Override this
if you want special behaviour for printing.g
- the Graphics context to print ontoprotected void printChildren(Graphics g)
paintChildren(java.awt.Graphics)
. Override this
if you want special behaviour for printing.g
- the Graphics context to print ontoprotected void printBorder(Graphics g)
paintBorder(java.awt.Graphics)
. Override this
if you want special behaviour for printing.g
- the Graphics context to print ontoprotected void processMouseMotionEvent(MouseEvent ev)
processMouseMotionEvent
in class Component
ev
- the MouseEvent describing the mouse motionMouseMotionListener
,
Component.addMouseMotionListener(MouseMotionListener)
,
Component.enableEvents(long)