|
JavaTM 2 Platform Std. Ed. v1.4.1 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent
The base class for all Swing components except top-level containers.
To use a component that inherits from JComponent
,
you must place the component in a containment hierarchy
whose root is a top-level Swing container.
Top-level Swing containers --
such as JFrame
, JDialog
,
and JApplet
--
are specialized components
that provide a place for other Swing components to paint themselves.
For an explanation of containment hierarchies, see
Swing Components and the Containment Hierarchy,
a section in The Java Tutorial.
The JComponent
class provides:
ComponentUI
.
See How
to Set the Look and Feel
in The Java Tutorial
for more information.
JComponent
contains all of the methods in the
Accessible
interface,
but it doesn't actually implement the interface. That is the
responsibility of the individual classes
that extend JComponent
.
putClientProperty(java.lang.Object, java.lang.Object)
and getClientProperty(java.lang.Object)
methods,
you can associate name-object pairs
with any object that descends from JComponent
.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans
package.
Please see XMLEncoder
.
KeyStroke
,
Action
,
setBorder(javax.swing.border.Border)
,
registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)
,
JOptionPane
,
setDebugGraphicsOptions(int)
,
setToolTipText(java.lang.String)
,
setAutoscrolls(boolean)
Nested Class Summary | |
class |
JComponent.AccessibleJComponent
Inner class of JComponent used to provide default support for accessibility. |
Nested classes inherited from class java.awt.Container |
|
Nested classes inherited from class java.awt.Component |
Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
protected AccessibleContext |
accessibleContext
The AccessibleContext associated with this
JComponent . |
protected EventListenerList |
listenerList
A list of event listeners for this component. |
static String |
TOOL_TIP_TEXT_KEY
The comment to display when the cursor is over the component, also known as a "value tip", "flyover help", or "flyover label". |
protected ComponentUI |
ui
The look and feel delegate for this component. |
static int |
UNDEFINED_CONDITION
Constant used by some of the APIs to mean that no condition is defined. |
static int |
WHEN_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. |
static int |
WHEN_FOCUSED
Constant used for registerKeyboardAction that
means that the command should be invoked when
the component has the focus. |
static int |
WHEN_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. |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
JComponent()
Default JComponent constructor. |
Method Summary | |
void |
addAncestorListener(AncestorListener listener)
Registers listener so that it will receive
AncestorEvents when it or any of its ancestors
move or are made visible or invisible. |
void |
addNotify()
Notifies this component that it now has a parent component. |
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. |
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Adds a PropertyChangeListener for a specific property. |
void |
addVetoableChangeListener(VetoableChangeListener listener)
Adds a VetoableChangeListener to the listener list. |
void |
computeVisibleRect(Rectangle visibleRect)
Returns the Component 's "visible rect rectangle" - the
intersection of the visible rectangles for this component
and all of its ancestors. |
boolean |
contains(int x,
int y)
Gives the UI delegate an opportunity to define the precise shape of this component for the sake of mouse processing. |
JToolTip |
createToolTip()
Returns the instance of JToolTip that should be used
to display the tooltip. |
void |
disable()
Deprecated. As of JDK version 1.1, replaced by java.awt.Component.setEnable(boolean) . |
void |
enable()
Deprecated. As of JDK version 1.1, replaced by java.awt.Component.setEnable(boolean) . |
void |
firePropertyChange(String propertyName,
boolean oldValue,
boolean newValue)
Reports a bound property change. |
void |
firePropertyChange(String propertyName,
byte oldValue,
byte newValue)
Reports a bound property change. |
void |
firePropertyChange(String propertyName,
char oldValue,
char newValue)
Reports a bound property change. |
void |
firePropertyChange(String propertyName,
double oldValue,
double newValue)
Reports a bound property change. |
void |
firePropertyChange(String propertyName,
float oldValue,
float newValue)
Reports a bound property change. |
void |
firePropertyChange(String propertyName,
int oldValue,
int newValue)
Reports a bound property change. |
void |
firePropertyChange(String propertyName,
long oldValue,
long newValue)
Reports a bound property change. |
protected void |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
Supports reporting bound property changes. |
void |
firePropertyChange(String propertyName,
short oldValue,
short newValue)
Reports a bound property change. |
protected void |
fireVetoableChange(String propertyName,
Object oldValue,
Object newValue)
Supports reporting constrained property changes. |
AccessibleContext |
getAccessibleContext()
Returns the AccessibleContext associated with this
JComponent . |
ActionListener |
getActionForKeyStroke(KeyStroke aKeyStroke)
Returns the object that will perform the action registered for a given keystroke. |
ActionMap |
getActionMap()
Returns the ActionMap used to determine what
Action to fire for particular KeyStroke
binding. |
float |
getAlignmentX()
Overrides Container.getAlignmentX to return
the vertical alignment. |
float |
getAlignmentY()
Overrides Container.getAlignmentY to return
the horizontal alignment. |
AncestorListener[] |
getAncestorListeners()
Returns an array of all the ancestor listeners registered on this component. |
boolean |
getAutoscrolls()
Gets the autoscrolls property. |
Border |
getBorder()
Returns the border of this component or null if no
border is currently set. |
Rectangle |
getBounds(Rectangle rv)
Stores the bounds of this component into "return value" rv and returns rv . |
Object |
getClientProperty(Object key)
Returns the value of the property with the specified key. |
protected Graphics |
getComponentGraphics(Graphics g)
Returns the graphics object used to paint this component. |
int |
getConditionForKeyStroke(KeyStroke aKeyStroke)
Returns the condition that determines whether a registered action occurs in response to the specified keystroke. |
int |
getDebugGraphicsOptions()
Returns the state of graphics debugging. |
static Locale |
getDefaultLocale()
Returns the default locale used to initialize each JComponent's locale property upon creation. |
Graphics |
getGraphics()
Returns this component's graphics context, which lets you draw on a component. |
int |
getHeight()
Returns the current height of this component. |
InputMap |
getInputMap()
Returns the InputMap that is used when the
component has focus. |
InputMap |
getInputMap(int condition)
Returns the InputMap that is used during
condition . |
InputVerifier |
getInputVerifier()
Returns the input verifier for this component. |
Insets |
getInsets()
If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets . |
Insets |
getInsets(Insets insets)
Returns an Insets object containing this component's inset
values. |
EventListener[] |
getListeners(Class listenerType)
Returns an array of all the objects currently registered as FooListener s
upon this JComponent . |
Point |
getLocation(Point rv)
Stores the x,y origin of this component into "return value" rv and returns rv . |
Dimension |
getMaximumSize()
If the maximum size has been set to a non- null value
just returns it. |
Dimension |
getMinimumSize()
If the minimum size has been set to a non- null value
just returns it. |
Component |
getNextFocusableComponent()
Deprecated. As of 1.4, replaced by FocusTraversalPolicy . |
Dimension |
getPreferredSize()
If the preferredSize has been set to a
non-null value just returns it. |
PropertyChangeListener[] |
getPropertyChangeListeners()
Returns an array of all the PropertyChangeListener s
added to this Component with addPropertyChangeListener(). |
PropertyChangeListener[] |
getPropertyChangeListeners(String propertyName)
Returns an array of all the listeners which have been associated with the named property. |
KeyStroke[] |
getRegisteredKeyStrokes()
Returns the KeyStrokes that will initiate
registered actions. |
JRootPane |
getRootPane()
Returns the JRootPane ancestor for this component. |
Dimension |
getSize(Dimension rv)
Stores the width/height of this component into "return value" rv and returns rv . |
Point |
getToolTipLocation(MouseEvent event)
Returns the tooltip location in this component's coordinate system. |
String |
getToolTipText()
Returns the tooltip string that has been set with setToolTipText . |
String |
getToolTipText(MouseEvent event)
Returns the string to be used as the tooltip for event. |
Container |
getTopLevelAncestor()
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. |
TransferHandler |
getTransferHandler()
Gets the transferHandler property. |
String |
getUIClassID()
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. |
boolean |
getVerifyInputWhenFocusTarget()
Returns the value that indicates whether the input verifier for the current focus owner will be called before this component requests focus. |
VetoableChangeListener[] |
getVetoableChangeListeners()
Returns an array of all the vetoable change listeners registered on this component. |
Rectangle |
getVisibleRect()
Returns the Component 's "visible rectangle" - the
intersection of this component's visible rectangle:
|
int |
getWidth()
Returns the current width of this component. |
int |
getX()
Returns the current x coordinate of the component's origin. |
int |
getY()
Returns the current y coordinate of the component's origin. |
void |
grabFocus()
Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. |
boolean |
isDoubleBuffered()
Returns whether this component should use a buffer to paint. |
static boolean |
isLightweightComponent(Component c)
Returns true if this component is lightweight, that is, if it doesn't have a native window system peer. |
boolean |
isManagingFocus()
Deprecated. As of 1.4, replaced by Component.setFocusTraversalKeys(int, Set) and
Container.setFocusCycleRoot(boolean) . |
boolean |
isMaximumSizeSet()
Returns true if the maximum size has been set to a non- null
value otherwise returns false. |
boolean |
isMinimumSizeSet()
Returns true if the minimum size has been set to a non- null
value otherwise returns false. |
boolean |
isOpaque()
Returns true if this component is completely opaque. |
boolean |
isOptimizedDrawingEnabled()
Returns true if this component tiles its children -- that is, if it can guarantee that the children will not overlap. |
boolean |
isPaintingTile()
Returns true if the component is currently painting a tile. |
boolean |
isPreferredSizeSet()
Returns true if the preferred size has been set to a non- null value otherwise returns false. |
boolean |
isRequestFocusEnabled()
Returns true if this JComponent should
get focus; otherwise returns false . |
boolean |
isValidateRoot()
If this method returns true, revalidate calls by
descendants of this component will cause the entire tree
beginning with this root to be validated. |
void |
paint(Graphics g)
Invoked by Swing to draw components. |
protected void |
paintBorder(Graphics g)
Paints the component's border. |
protected void |
paintChildren(Graphics g)
Paints this component's children. |
protected void |
paintComponent(Graphics g)
Calls the UI delegate's paint method, if the UI delegate is non- null . |
void |
paintImmediately(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. |
void |
paintImmediately(Rectangle r)
Paints the specified region now. |
protected String |
paramString()
Returns a string representation of this JComponent . |
void |
print(Graphics g)
Invoke this method to print the component. |
void |
printAll(Graphics g)
Invoke this method to print the component. |
protected void |
printBorder(Graphics g)
Prints the component's border. |
protected void |
printChildren(Graphics g)
Prints this component's children. |
protected void |
printComponent(Graphics g)
This is invoked during a printing operation. |
protected void |
processComponentKeyEvent(KeyEvent e)
Processes any key events that the component itself recognizes. |
protected boolean |
processKeyBinding(KeyStroke ks,
KeyEvent e,
int condition,
boolean pressed)
Invoked to process the key bindings for ks as the result
of the KeyEvent e . |
protected void |
processKeyEvent(KeyEvent e)
Overrides processKeyEvent to process events. |
protected void |
processMouseMotionEvent(MouseEvent e)
Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED. |
void |
putClientProperty(Object key,
Object value)
Adds an arbitrary key/value "client property" to this component. |
void |
registerKeyboardAction(ActionListener anAction,
KeyStroke aKeyStroke,
int aCondition)
This method is now obsolete, please use a combination of getActionMap() and getInputMap() for
similiar behavior. |
void |
registerKeyboardAction(ActionListener anAction,
String aCommand,
KeyStroke aKeyStroke,
int aCondition)
This method is now obsolete, please use a combination of getActionMap() and getInputMap() for
similiar behavior. |
void |
removeAncestorListener(AncestorListener listener)
Unregisters listener so that it will no longer receive
AncestorEvents . |
void |
removeNotify()
Notifies this component that it no longer has a parent component. |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. |
void |
removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Removes a PropertyChangeListener for a specific property. |
void |
removeVetoableChangeListener(VetoableChangeListener listener)
Removes a VetoableChangeListener from the listener list. |
void |
repaint(long tm,
int x,
int y,
int width,
int height)
Adds the specified region to the dirty region list if the component is showing. |
void |
repaint(Rectangle r)
Adds the specified region to the dirty region list if the component is showing. |
boolean |
requestDefaultFocus()
Deprecated. As of 1.4, replaced by FocusTraversalPolicy.getDefaultComponent(Container).requestFocus() |
void |
requestFocus()
Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window. |
boolean |
requestFocus(boolean temporary)
JComponent overrides requestFocus solely
to make the method public so that UI implementations can cause
temporary focus changes. |
boolean |
requestFocusInWindow()
Requests that this Component get the input focus, if this Component's top-level ancestor is already the focused Window. |
protected boolean |
requestFocusInWindow(boolean temporary)
JComponent overrides requestFocusInWindow
solely to make the method public so that UI implementations can cause
temporary focus changes. |
void |
resetKeyboardActions()
Unregisters all the bindings in the first tier InputMaps
and ActionMap . |
void |
reshape(int x,
int y,
int w,
int h)
Moves and resizes this component. |
void |
revalidate()
Supports deferred automatic layout. |
void |
scrollRectToVisible(Rectangle aRect)
Forwards the scrollRectToVisible() message to the
JComponent 's parent. |
void |
setActionMap(ActionMap am)
Sets the ActionMap to am . |
void |
setAlignmentX(float alignmentX)
Sets the the vertical alignment. |
void |
setAlignmentY(float alignmentY)
Sets the the horizontal alignment. |
void |
setAutoscrolls(boolean autoscrolls)
Sets the autoscrolls property. |
void |
setBackground(Color bg)
Sets the background color of this component. |
void |
setBorder(Border border)
Sets the border of this component. |
void |
setDebugGraphicsOptions(int debugOptions)
Enables or disables diagnostic information about every graphics operation performed within the component or one of its children. |
static void |
setDefaultLocale(Locale l)
Sets the default locale used to initialize each JComponent's locale property upon creation. |
void |
setDoubleBuffered(boolean aFlag)
Sets whether the this component should use a buffer to paint. |
void |
setEnabled(boolean enabled)
Sets whether or not this component is enabled. |
void |
setFont(Font font)
Sets the font for this component. |
void |
setForeground(Color fg)
Sets the foreground color of this component. |
void |
setInputMap(int condition,
InputMap map)
Sets the InputMap to use under the condition
condition to
map . |
void |
setInputVerifier(InputVerifier inputVerifier)
Sets the input verifier for this component. |
void |
setMaximumSize(Dimension maximumSize)
Sets the maximum size of this component to a constant value. |
void |
setMinimumSize(Dimension minimumSize)
Sets the minimum size of this component to a constant value. |
void |
setNextFocusableComponent(Component aComponent)
Deprecated. As of 1.4, replaced by FocusTraversalPolicy |
void |
setOpaque(boolean isOpaque)
If true the component paints every pixel within its bounds. |
void |
setPreferredSize(Dimension preferredSize)
Sets the preferred size of this component. |
void |
setRequestFocusEnabled(boolean requestFocusEnabled)
Provides a hint as to whether or not this JComponent
should get focus. |
void |
setToolTipText(String text)
Registers the text to display in a tool tip. |
void |
setTransferHandler(TransferHandler newHandler)
Sets the transferHandler property,
which is null if the component does
not support data transfer operations. |
protected void |
setUI(ComponentUI newUI)
Sets the look and feel delegate for this component. |
void |
setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget)
Sets the value to indicate whether input verifier for the current focus owner will be called before this component requests focus. |
void |
setVisible(boolean aFlag)
Makes the component visible or invisible. |
void |
unregisterKeyboardAction(KeyStroke aKeyStroke)
This method is now obsolete. |
void |
update(Graphics g)
Calls paint . |
void |
updateUI()
Resets the UI property to a value from the current look and feel. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected transient ComponentUI ui
protected EventListenerList listenerList
public static final int WHEN_FOCUSED
registerKeyboardAction
that
means that the command should be invoked when
the component has the focus.
public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
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.
public static final int WHEN_IN_FOCUSED_WINDOW
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.
public static final int UNDEFINED_CONDITION
public static final String TOOL_TIP_TEXT_KEY
protected AccessibleContext accessibleContext
AccessibleContext
associated with this
JComponent
.
Constructor Detail |
public JComponent()
JComponent
constructor. This constructor does
very little initialization beyond calling the Container
constructor. For example, the initial layout manager is
null
. It does, however, set the component's locale
property to the value returned by
JComponent.getDefaultLocale
.
getDefaultLocale()
Method Detail |
public void updateUI()
JComponent
subclasses must override this method
like this:
public void updateUI() { setUI((SliderUI)UIManager.getUI(this); }
setUI(javax.swing.plaf.ComponentUI)
,
UIManager.getLookAndFeel()
,
UIManager.getUI(javax.swing.JComponent)
protected void setUI(ComponentUI newUI)
JComponent
subclasses generally override this method
to narrow the argument type. For example, in JSlider
:
public void setUI(SliderUI newUI) { super.setUI(newUI); }
Additionally JComponent
subclasses must provide a
getUI
method that returns the correct type. For example:
public SliderUI getUI() { return (SliderUI)ui; }
newUI
- the new UI delegateupdateUI()
,
UIManager.getLookAndFeel()
,
UIManager.getUI(javax.swing.JComponent)
public String getUIClassID()
UIDefaults
key used to
look up the name of the swing.plaf.ComponentUI
class that defines the look and feel
for this component. Most applications will never need to
call this method. Subclasses of JComponent
that support
pluggable look and feel should override this method to
return a UIDefaults
key that maps to the
ComponentUI
subclass that defines their look and feel.
UIDefaults
key for a
ComponentUI
subclassUIDefaults.getUI(javax.swing.JComponent)
protected Graphics getComponentGraphics(Graphics g)
DebugGraphics
is turned on we create a new
DebugGraphics
object if necessary.
Otherwise we just configure the
specified graphics object's foreground and font.
g
- the original Graphics
object
Graphics
object configured for this componentprotected void paintComponent(Graphics g)
null
. We pass the delegate a copy of the
Graphics
object to protect the rest of the
paint code from irrevocable changes
(for example, Graphics.translate
).
If you override this in a subclass you should not make permanent
changes to the passed in Graphics
. For example, you
should not alter the clip Rectangle
or modify the
transform. If you need to do these operations you may find it
easier to create a new Graphics
from the passed in
Graphics
and manipulate it. Further, if you do not
invoker super's implementation you must honor the opaque property,
that is
if this component is opaque, you must completely fill in the background
in a non-opaque color. If you do not honor the opaque property you
will likely see visual artifacts.
g
- the Graphics
object to protectpaint(java.awt.Graphics)
,
ComponentUI
protected void paintChildren(Graphics g)
shouldUseBuffer
is true,
no component ancestor has a buffer and
the component children can use a buffer if they have one.
Otherwise, one ancestor has a buffer currently in use and children
should not use a buffer to paint.
g
- the Graphics
context in which to paintpaint(java.awt.Graphics)
,
Container.paint(java.awt.Graphics)
protected void paintBorder(Graphics g)
If you override this in a subclass you should not make permanent
changes to the passed in Graphics
. For example, you
should not alter the clip Rectangle
or modify the
transform. If you need to do these operations you may find it
easier to create a new Graphics
from the passed in
Graphics
and manipulate it.
g
- the Graphics
context in which to paintpaint(java.awt.Graphics)
,
setBorder(javax.swing.border.Border)
public void update(Graphics g)
paint
. Doesn't clear the background but see
ComponentUI.update
, which is called by
paintComponent
.
update
in class Container
g
- the Graphics
context in which to paintpaint(java.awt.Graphics)
,
paintComponent(java.awt.Graphics)
,
ComponentUI
public void paint(Graphics g)
paint
directly,
but should instead use the repaint
method to
schedule the component for redrawing.
This method actually delegates the work of painting to three
protected methods: paintComponent
,
paintBorder
,
and paintChildren
. They're called in the order
listed to ensure that children appear on top of component itself.
Generally speaking, the component and its children should not
paint in the insets area allocated to the border. Subclasses can
just override this method, as always. A subclass that just
wants to specialize the UI (look and feel) delegate's
paint
method should just override
paintComponent
.
paint
in class Container
g
- the Graphics
context in which to paintpaintComponent(java.awt.Graphics)
,
paintBorder(java.awt.Graphics)
,
paintChildren(java.awt.Graphics)
,
getComponentGraphics(java.awt.Graphics)
,
repaint(long, int, int, int, int)
public void printAll(Graphics g)
print
on the component.
printAll
in class Component
g
- the Graphics
context in which to paintprint(java.awt.Graphics)
,
printComponent(java.awt.Graphics)
,
printBorder(java.awt.Graphics)
,
printChildren(java.awt.Graphics)
public void print(Graphics g)
printComponent
,
printBorder
and printChildren
. It is
not recommended that you override this method, instead override
one of the previously mentioned methods. This method sets the
component's state such that the double buffer will not be used, eg
painting will be done directly on the passed in Graphics
.
print
in class Container
g
- the Graphics
context in which to paintprintComponent(java.awt.Graphics)
,
printBorder(java.awt.Graphics)
,
printChildren(java.awt.Graphics)
protected void printComponent(Graphics g)
paintComponent
on the component. Override this
if you wish to add special painting behavior when printing.
g
- the Graphics
context in which to paintprint(java.awt.Graphics)
protected void printChildren(Graphics g)
paintChildren
on the component. Override this if you
wish to print the children differently than painting.
g
- the Graphics
context in which to paintprint(java.awt.Graphics)
protected void printBorder(Graphics g)
paintBorder
on the component. Override this if you
wish to print the border differently that it is painted.
g
- the Graphics
context in which to paintprint(java.awt.Graphics)
public boolean isPaintingTile()
public boolean isManagingFocus()
Component.setFocusTraversalKeys(int, Set)
and
Container.setFocusCycleRoot(boolean)
.
JComponent
's focus traversal keys to
CTRL+TAB and CTRL+SHIFT+TAB. Also prevents
SortingFocusTraversalPolicy
from considering descendants
of this JComponent when computing a focus traversal cycle.
Component.setFocusTraversalKeys(int, java.util.Set)
,
SortingFocusTraversalPolicy
public void setNextFocusableComponent(Component aComponent)
FocusTraversalPolicy
FocusTraversalPolicy
for this
JComponent
's focus traversal cycle by unconditionally
setting the specified Component
as the next
Component
in the cycle, and this JComponent
as the specified Component
's previous
Component
in the cycle.
aComponent
- the Component
that should follow this
JComponent
in the focus traversal cyclegetNextFocusableComponent()
,
FocusTraversalPolicy
public Component getNextFocusableComponent()
FocusTraversalPolicy
.
Component
set by a prior call to
setNextFocusableComponent(Component)
on this
JComponent
.
Component
that will follow this
JComponent
in the focus traversal cycle, or
null
if none has been explicitly specifiedsetNextFocusableComponent(java.awt.Component)
public void setRequestFocusEnabled(boolean requestFocusEnabled)
JComponent
should get focus. This is only a hint, and it is up to consumers that
are requesting focus to honor this property. This is typically honored
for mouse operations, but not keyboard operations. For example, look
and feels could verify this property is true before requesting focus
during a mouse operation. This would often times be used if you did
not want a mouse press on a JComponent
to steal focus,
but did want the JComponent
to be traversable via the
keyboard. If you do not want this JComponent
focusable at
all, use the setFocusable
method instead.
requestFocusEnabled
- Indicates if you want this JComponent to
be focusable or notComponent.setFocusable(boolean)
public boolean isRequestFocusEnabled()
true
if this JComponent
should
get focus; otherwise returns false
.
true
if this component should get focus,
otherwise returns false
setRequestFocusEnabled(boolean)
,
Focus
Specification,
Component.isFocusable()
public void requestFocus()
Component
This method cannot be used to set the focus owner to no Component at
all. Use KeyboardFocusManager.clearGlobalFocusOwner()
instead.
Because the focus behavior of this method is platform-dependent,
developers are strongly encouraged to use
requestFocusInWindow
when possible.
requestFocus
in class Component
Component.requestFocusInWindow()
,
FocusEvent
,
Component.addFocusListener(java.awt.event.FocusListener)
,
Component.isFocusable()
,
Component.isDisplayable()
,
KeyboardFocusManager.clearGlobalFocusOwner()
public boolean requestFocus(boolean temporary)
JComponent
overrides requestFocus
solely
to make the method public so that UI implementations can cause
temporary focus changes. This method is not meant for general use,
instead developers are urged to call the noarg requestFocus
or requestFocusInWindow
methods. If the
JComponent
has an InputVerifier
associated
with it, the InputVerifier
will be messaged.
Refer to Component.requestFocus(boolean)
for a complete description
of this method.
requestFocus
in class Component
temporary
- boolean indicating if the focus change is temporary
false
if the focus change request is guaranteed to
fail; true
if it is likely to succeedComponent.requestFocus()
,
Component.requestFocusInWindow()
,
Component.requestFocus(boolean)
,
Component.requestFocusInWindow(boolean)
public boolean requestFocusInWindow()
Component
This method returns a boolean value. If false
is returned,
the request is guaranteed to fail. If true
is
returned, the request will succeed unless it is vetoed, or an
extraordinary event, such as disposal of the Component's peer, occurs
before the request can be granted by the native windowing system. Again,
while a return value of true
indicates that the request is
likely to succeed, developers must never assume that this Component is
the focus owner until this Component receives a FOCUS_GAINED event.
This method cannot be used to set the focus owner to no Component at
all. Use KeyboardFocusManager.clearGlobalFocusOwner()
instead.
The focus behavior of this method can be implemented uniformly across
platforms, and thus developers are strongly encouraged to use this
method over requestFocus
when possible. Code which relies
on requestFocus
may exhibit different focus behavior on
different platforms.
requestFocusInWindow
in class Component
false
if the focus change request is guaranteed to
fail; true
if it is likely to succeedComponent.requestFocus()
,
FocusEvent
,
Component.addFocusListener(java.awt.event.FocusListener)
,
Component.isFocusable()
,
Component.isDisplayable()
,
KeyboardFocusManager.clearGlobalFocusOwner()
protected boolean requestFocusInWindow(boolean temporary)
JComponent
overrides requestFocusInWindow
solely to make the method public so that UI implementations can cause
temporary focus changes. This method is not meant for general use,
instead developers are urged to call the noarg requestFocus
or requestFocusInWindow
methods. If the
JComponent
has an InputVerifier
associated
with it, the InputVerifier
will be messaged.
Refer to Component.requestFocusInWindow(boolean)
for a complete description of
this method.
requestFocusInWindow
in class Component
temporary
- boolean indicating if the focus change is temporary
false
if the focus change request is guaranteed to
fail; true
if it is likely to succeedComponent.requestFocus()
,
Component.requestFocusInWindow()
,
Component.requestFocus(boolean)
,
Component.requestFocusInWindow(boolean)
public void grabFocus()
This method is intended for use by focus implementations. Client code
should not use this method; instead, it should use
requestFocus()
.
requestFocus()
public void setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget)
InputVerifier
,
setInputVerifier(javax.swing.InputVerifier)
,
getInputVerifier()
,
getVerifyInputWhenFocusTarget()
public boolean getVerifyInputWhenFocusTarget()
verifyInputWhenFocusTarget
propertyInputVerifier
,
setInputVerifier(javax.swing.InputVerifier)
,
getInputVerifier()
,
setVerifyInputWhenFocusTarget(boolean)
public void setPreferredSize(Dimension preferredSize)
preferredSize
is null
, the UI will
be asked for the preferred size.
public Dimension getPreferredSize()
preferredSize
has been set to a
non-null
value just returns it.
If the UI delegate's getPreferredSize
method returns a non null
value then return that;
otherwise defer to the component's layout manager.
getPreferredSize
in class Container
preferredSize
propertysetPreferredSize(java.awt.Dimension)
,
ComponentUI
public void setMaximumSize(Dimension maximumSize)
getMaximumSize
will always
return this value; the component's UI will not be asked
to compute it. Setting the maximum size to null
restores the default behavior.
maximumSize
- a Dimension
containing the
desired maximum allowable sizegetMaximumSize()
public Dimension getMaximumSize()
null
value
just returns it. If the UI delegate's getMaximumSize
method returns a non-null
value then return that;
otherwise defer to the component's layout manager.
getMaximumSize
in class Container
maximumSize
propertysetMaximumSize(java.awt.Dimension)
,
ComponentUI
public void setMinimumSize(Dimension minimumSize)
getMinimumSize
will always
return this value; the component's UI will not be asked
to compute it. Setting the minimum size to null
restores the default behavior.
minimumSize
- the new minimum size of this componentgetMinimumSize()
public Dimension getMinimumSize()
null
value
just returns it. If the UI delegate's getMinimumSize
method returns a non-null
value then return that; otherwise
defer to the component's layout manager.
getMinimumSize
in class Container
minimumSize
propertysetMinimumSize(java.awt.Dimension)
,
ComponentUI
public boolean isMinimumSizeSet()
null
value otherwise returns false.
minimumSize
is non-null
,
false otherwisepublic boolean isPreferredSizeSet()
null
value otherwise returns false.
preferredSize
is non-null
,
false otherwisepublic boolean isMaximumSizeSet()
null
value otherwise returns false.
maximumSize
is non-null
,
false otherwisepublic boolean contains(int x, int y)
contains
in class Component
x
- the x coordinate of the pointy
- the y coordinate of the point
Component.contains(int, int)
,
ComponentUI
public void setBorder(Border border)
Border
object is
responsible for defining the insets for the component
(overriding any insets set directly on the component) and
for optionally rendering any border decorations within the
bounds of those insets. Borders should be used (rather
than insets) for creating both decorative and non-decorative
(such as margins and padding) regions for a swing component.
Compound borders can be used to nest multiple borders within a
single component.
This is a bound property.
border
- the border to be rendered for this componentBorder
,
CompoundBorder
public Border getBorder()
null
if no
border is currently set.
setBorder(javax.swing.border.Border)
public Insets getInsets()
super.getInsets
.
getInsets
in class Container
setBorder(javax.swing.border.Border)
public Insets getInsets(Insets insets)
Insets
object containing this component's inset
values. The passed-in Insets
object will be reused
if possible.
Calling methods cannot assume that the same object will be returned,
however. All existing values within this object are overwritten.
If insets
is null, this will allocate a new one.
insets
- the Insets
object, which can be reused
Insets
objectgetInsets()
public float getAlignmentY()
Container.getAlignmentY
to return
the horizontal alignment.
getAlignmentY
in class Container
alignmentY
propertysetAlignmentY(float)
,
Component.getAlignmentY()
public void setAlignmentY(float alignmentY)
alignmentY
- the new horizontal alignmentgetAlignmentY()
public float getAlignmentX()
Container.getAlignmentX
to return
the vertical alignment.
getAlignmentX
in class Container
alignmentX
propertysetAlignmentX(float)
,
Component.getAlignmentX()
public void setAlignmentX(float alignmentX)
alignmentX
- the new vertical alignmentgetAlignmentX()
public void setInputVerifier(InputVerifier inputVerifier)
inputVerifier
- the new input verifierInputVerifier
public InputVerifier getInputVerifier()
inputVerifier
propertyInputVerifier
public Graphics getGraphics()
Graphics
object and
then invoke operations on that object to draw on the component.
getGraphics
in class Component
Component.paint(java.awt.Graphics)
public void setDebugGraphicsOptions(int debugOptions)
debugOptions
- determines how the component should display
the information; one of the following options:
ExternalWindow
that displays the operations
performed on the View's offscreen buffer.
debugOptions
is bitwise OR'd into the current valuepublic int getDebugGraphicsOptions()
ExternalWindow
that displays the operations
performed on the View's offscreen buffer.
setDebugGraphicsOptions(int)
public void registerKeyboardAction(ActionListener anAction, String aCommand, KeyStroke aKeyStroke, int aCondition)
getActionMap()
and getInputMap()
for
similiar behavior. For example, to bind the KeyStroke
aKeyStroke
to the Action
anAction
now use:
component.getInputMap().put(aKeyStroke, aCommand); component.getActionMap().put(aCommmand, anAction);The above assumes you want the binding to be applicable for
WHEN_FOCUSED
. To register bindings for other focus
states use the getInputMap
method that takes an integer.
Register a new keyboard action.
anAction
will be invoked if a key event matching
aKeyStroke
occurs and aCondition
is verified.
The KeyStroke
object defines a
particular combination of a keyboard key and one or more modifiers
(alt, shift, ctrl, meta).
The aCommand
will be set in the delivered event if
specified.
The aCondition
can be one of:
- WHEN_FOCUSED
- The action will be invoked only when the keystroke occurs while the component has the focus.
- WHEN_IN_FOCUSED_WINDOW
- The action will be invoked when the keystroke occurs while the component has the focus or if the component is in the window that has the focus. Note that the component need not be an immediate descendent of the window -- it can be anywhere in the window's containment hierarchy. In other words, whenever any component in the window has the focus, the action registered with this component is invoked.
- WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
- The action will be invoked when the keystroke occurs while the component has the focus or if the component is an ancestor of the component that has the focus.
The combination of keystrokes and conditions lets you define high level (semantic) action events for a specified keystroke+modifier combination (using the KeyStroke class) and direct to a parent or child of a component that has the focus, or to the component itself. In other words, in any hierarchical structure of components, an arbitrary key-combination can be immediately directed to the appropriate component in the hierarchy, and cause a specific method to be invoked (usually by way of adapter objects).
If an action has already been registered for the receiving
container, with the same charCode and the same modifiers,
anAction
will replace the action.
anAction
- the Action
to be registeredaCommand
- the command to be set in the delivered eventaKeyStroke
- the KeyStroke
to bind to the actionaCondition
- the condition that needs to be met, see aboveKeyStroke
public void registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition)
getActionMap()
and getInputMap()
for
similiar behavior.
public void unregisterKeyboardAction(KeyStroke aKeyStroke)
ActionMap/InputMap
, or place a dummy binding the
InputMap
. Removing the binding from the
InputMap
allows bindings in parent InputMap
s
to be active, whereas putting a dummy binding in the
InputMap
effectively disables
the binding from ever happening.
Unregisters a keyboard action.
This will remove the binding from the ActionMap
(if it exists) as well as the InputMap
s.
public KeyStroke[] getRegisteredKeyStrokes()
KeyStrokes
that will initiate
registered actions.
KeyStroke
objectsregisterKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)
public int getConditionForKeyStroke(KeyStroke aKeyStroke)
For Java 2 platform v1.3, a KeyStroke
can be associated
with more than one condition.
For example, 'a' could be bound for the two
conditions WHEN_FOCUSED
and
WHEN_IN_FOCUSED_WINDOW
condition.
public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
ActionListener
object invoked when the keystroke occurspublic void resetKeyboardActions()
InputMaps
and ActionMap
. This has the effect of removing any
local bindings, and allowing the bindings defined in parent
InputMap/ActionMaps
(the UI is usually defined in the second tier) to persist.
public final void setInputMap(int condition, InputMap map)
InputMap
to use under the condition
condition
to
map
. A null
value implies you
do not want any bindings to be used, even from the UI. This will
not reinstall the UI InputMap
(if there was one).
condition
has one of the following values:
WHEN_IN_FOCUSED_WINDOW
WHEN_FOCUSED
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
condition
is WHEN_IN_FOCUSED_WINDOW
and map
is not a ComponentInputMap
, an
IllegalArgumentException
will be thrown.
Similarly, if condition
is not one of the values
listed, an IllegalArgumentException
will be thrown.
condition
- one of the values listed abovemap
- the InputMap
to use for the given condition
IllegalArgumentException
- if condition
is
WHEN_IN_FOCUSED_WINDOW
and map
is not an instance of ComponentInputMap
; or
if condition
is not one of the legal values
specified abovepublic final InputMap getInputMap(int condition)
InputMap
that is used during
condition
.
condition
- one of WHEN_IN_FOCUSED_WINDOW, WHEN_FOCUSED,
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
InputMap
for the specified
condition
public final InputMap getInputMap()
InputMap
that is used when the
component has focus.
This is convenience method for getInputMap(WHEN_FOCUSED)
.
InputMap
used when the component has focuspublic final void setActionMap(ActionMap am)
ActionMap
to am
. This does not set
the parent of the am
to be the ActionMap
from the UI (if there was one), it is up to the caller to have done this.
am
- the new ActionMap
public final ActionMap getActionMap()
ActionMap
used to determine what
Action
to fire for particular KeyStroke
binding. The returned ActionMap
, unless otherwise
set, will have the ActionMap
from the UI set as the parent.
ActionMap
containing the key/action bindingspublic boolean requestDefaultFocus()
FocusTraversalPolicy.getDefaultComponent(Container).requestFocus()
JComponent
's
FocusTraversalPolicy
's default Component
.
If this JComponent
is a focus cycle root, then its
FocusTraversalPolicy
is used. Otherwise, the
FocusTraversalPolicy
of this JComponent
's
focus-cycle-root ancestor is used.
FocusTraversalPolicy.getDefaultComponent(java.awt.Container)
public void setVisible(boolean aFlag)
Component.setVisible
.
setVisible
in class Component
aFlag
- true to make the component visible; false to
make it invisibleComponent.isVisible()
public void setEnabled(boolean enabled)
Note: Disabling a component does not disable it's children.
Note: Disabling a lightweight component does not prevent it from receiving MouseEvents.
setEnabled
in class Component
enabled
- true if this component should be enabled, false otherwiseComponent.isEnabled()
,
Component.isLightweight()
public void setForeground(Color fg)
setForeground
in class Component
fg
- the desired foreground Color
Component.getForeground()
public void setBackground(Color bg)
setBackground
in class Component
bg
- the desired background Color
Component.getBackground()
public void setFont(Font font)
setFont
in class Container
font
- The font to become this container's font.Component.getFont()
public static Locale getDefaultLocale()
Locale
.setDefaultLocale(java.util.Locale)
,
Component.getLocale()
,
Component.setLocale(java.util.Locale)
public static void setDefaultLocale(Locale l)
l
- the desired default Locale
for new components.getDefaultLocale()
,
Component.getLocale()
,
Component.setLocale(java.util.Locale)
protected void processComponentKeyEvent(KeyEvent e)
This method is implemented to do nothing. Subclasses would normally override this method if they process some key events themselves. If the event is processed, it should be consumed.
protected void processKeyEvent(KeyEvent e)
processKeyEvent
to process events.
processKeyEvent
in class Component
e
- the key eventKeyEvent
,
KeyListener
,
Component.addKeyListener(java.awt.event.KeyListener)
,
Component.enableEvents(long)
,
Component.isShowing()
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
ks
as the result
of the KeyEvent
e
. This obtains
the appropriate InputMap
,
gets the binding, gets the action from the ActionMap
,
and then (if the action is found and the component
is enabled) invokes notifyAction
to notify the action.
ks
- the KeyStroke
queriede
- the KeyEvent
condition
- one of the following values:
pressed
- true if the key is pressed
public void setToolTipText(String text)
See How to Use Tool Tips in The Java Tutorial for further documentation.
text
- the string to display; if the text is null
,
the tool tip is turned off for this componentTOOL_TIP_TEXT_KEY
public String getToolTipText()
setToolTipText
.
TOOL_TIP_TEXT_KEY
public String getToolTipText(MouseEvent event)
setToolTipText
. If a component provides
more extensive API to support differing tooltips at different locations,
this method should be overridden.
public Point getToolTipLocation(MouseEvent event)
null
is returned, Swing will choose a location.
The default implementation returns null
.
event
- the MouseEvent
that caused the
ToolTipManager
to show the tooltip
null
public JToolTip createToolTip()
JToolTip
that should be used
to display the tooltip.
Components typically would not override this method,
but it can be used to
cause different tooltips to be displayed differently.
JToolTip
used to display this toolTippublic void scrollRectToVisible(Rectangle aRect)
scrollRectToVisible()
message to the
JComponent
's parent. Components that can service
the request, such as JViewport
,
override this method and perform the scrolling.
aRect
- the visible Rectangle
JViewport
public void setAutoscrolls(boolean autoscrolls)
autoscrolls
property.
If true
mouse dragged events will be
synthetically generated when the mouse is dragged
outside of the component's bounds and mouse motion
has paused (while the button continues to be held
down). The synthetic events make it appear that the
drag gesture has resumed in the direction established when
the component's boundary was crossed. Components that
support autoscrolling must handle mouseDragged
events by calling scrollRectToVisible
with a
rectangle that contains the mouse event's location. All of
the Swing components that support item selection and are
typically displayed in a JScrollPane
(JTable
, JList
, JTree
,
JTextArea
, and JEditorPane
)
already handle mouse dragged events in this way. To enable
autoscrolling in any other component, add a mouse motion
listener that calls scrollRectToVisible
.
For example, given a JPanel
, myPanel
:
MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { Rectangle r = new Rectangle(e.getX(), e.getY(), 1, 1); ((JPanel)e.getSource()).scrollRectToVisible(r); } }; myPanel.addMouseMotionListener(doScrollRectToVisible);The default value of the
autoScrolls
property is false
.
autoscrolls
- if true, synthetic mouse dragged events
are generated when the mouse is dragged outside of a component's
bounds and the mouse button continues to be held down; otherwise
falsegetAutoscrolls()
,
JViewport
,
JScrollPane
public boolean getAutoscrolls()
autoscrolls
property.
autoscrolls
propertyJViewport
,
setAutoscrolls(boolean)
public void setTransferHandler(TransferHandler newHandler)
transferHandler
property,
which is null
if the component does
not support data transfer operations.
If newHandler
is not null, and the system property
suppressSwingDropSupport
is not true, this will
install a DropTarget
on the JComponent
.
The default for the system property is false, so that a
DropTarget
will be added.
newHandler
- mechanism for transfer of data to
and from the componentTransferHandler
,
getTransferHandler()
public TransferHandler getTransferHandler()
transferHandler
property.
transferHandler
propertyTransferHandler
,
setTransferHandler(javax.swing.TransferHandler)
protected void processMouseMotionEvent(MouseEvent e)
processMouseMotionEvent
in class Component
e
- the mouse motion eventMouseEvent
public void enable()
java.awt.Component.setEnable(boolean)
.
enable
in class Component
public void disable()
java.awt.Component.setEnable(boolean)
.
disable
in class Component
public AccessibleContext getAccessibleContext()
AccessibleContext
associated with this
JComponent
. The method implemented by this base
class returns null. Classes that extend JComponent
should implement this method to return the
AccessibleContext
associated with the subclass.
getAccessibleContext
in class Component
AccessibleContext
of this
JComponent
public final Object getClientProperty(Object key)
putClientProperty
will return
a non-null
value.
key
- the being queried
null
putClientProperty(java.lang.Object, java.lang.Object)
public final void putClientProperty(Object key, Object value)
The get/putClientProperty
methods provide access to
a small per-instance hashtable. Callers can use get/putClientProperty
to annotate components that were created by another module.
For example, a
layout manager might store per child constraints this way. For example:
componentA.putClientProperty("to the left of", componentB);If value is
null
this method will remove the property.
Changes to client properties are reported with
PropertyChange
events.
The name of the property (for the sake of PropertyChange
events) is key.toString()
.
The clientProperty
dictionary is not intended to
support large
scale extensions to JComponent nor should be it considered an
alternative to subclassing when designing a new component.
key
- the new client property keyvalue
- the new client property value; if null
this method will remove the propertygetClientProperty(java.lang.Object)
,
addPropertyChangeListener(java.beans.PropertyChangeListener)
public static boolean isLightweightComponent(Component c)
public void reshape(int x, int y, int w, int h)
reshape
in class Component
x
- the new horizontal locationy
- the new vertical locationw
- the new widthh
- the new heightComponent.setBounds(int, int, int, int)
public Rectangle getBounds(Rectangle rv)
rv
and returns rv
.
If rv
is null
a new Rectangle
is allocated. This version of getBounds
is useful
if the caller wants to avoid allocating a new Rectangle
object on the heap.
getBounds
in class Component
rv
- the return value, modified to the component's bounds
rv
; if rv
is null
return a newly created Rectangle
with this
component's boundspublic Dimension getSize(Dimension rv)
rv
and returns rv
.
If rv
is null
a new Dimension
object is allocated. This version of getSize
is useful if the caller wants to avoid allocating a new
Dimension
object on the heap.
getSize
in class Component
rv
- the return value, modified to the component's size
rv
public Point getLocation(Point rv)
rv
and returns rv
.
If rv
is null
a new Point
is allocated. This version of getLocation
is useful
if the caller wants to avoid allocating a new Point
object on the heap.
getLocation
in class Component
rv
- the return value, modified to the component's location
rv
public int getX()
component.getBounds().x
, or
component.getLocation().x
because it doesn't cause any
heap allocations.
getX
in class Component
public int getY()
component.getBounds().y
, or
component.getLocation().y
because it doesn't cause any
heap allocations.
getY
in class Component
public int getWidth()
component.getBounds().width
, or
component.getSize().width
because it doesn't cause any
heap allocations.
getWidth
in class Component
public int getHeight()
component.getBounds().height
, or
component.getSize().height
because it doesn't cause any
heap allocations.
getHeight
in class Component
public boolean isOpaque()
An opaque component paints every pixel within its rectangular bounds. A non-opaque component paints only a subset of its pixels or none at all, allowing the pixels underneath it to "show through". Therefore, a component that does not fully paint its pixels provides a degree of transparency.
Subclasses that guarantee to always completely paint their contents should override this method and return true.
isOpaque
in class Component
setOpaque(boolean)
public void setOpaque(boolean isOpaque)
The default value of this property is false for JComponent
.
However, the default value for this property on most standard
JComponent
subclasses (such as JButton
and
JTree
) is look-and-feel dependent.
isOpaque
- true if this component should be opaqueisOpaque()
public void computeVisibleRect(Rectangle visibleRect)
Component
's "visible rect rectangle" - the
intersection of the visible rectangles for this component
and all of its ancestors. The return value is stored in
visibleRect
.
visibleRect
- a Rectangle
computed as the
intersection of all visible rectangles for this
component and all of its ancestors -- this is the return
value for this methodgetVisibleRect()
public Rectangle getVisibleRect()
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.
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
oldValue
and newValue
are not equal and the
PropertyChangeEvent
listener list isn't empty,
then fire a PropertyChange
event to each listener.
This method has an overloaded method for each primitive type. For
example, here's how to write a bound property set method whose
value is an integer:
public void setFoo(int newValue) { int oldValue = foo; foo = newValue; firePropertyChange("foo", oldValue, newValue); }
firePropertyChange
in class Component
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as an Object)newValue
- the new value of the property (as an Object)PropertyChangeSupport
public void firePropertyChange(String propertyName, byte oldValue, byte newValue)
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as a byte)newValue
- the new value of the property (as a byte)firePropertyChange(java.lang.String, java.lang.Object,
java.lang.Object)
public void firePropertyChange(String propertyName, char oldValue, char newValue)
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as a char)newValue
- the new value of the property (as a char)firePropertyChange(java.lang.String, java.lang.Object,
java.lang.Object)
public void firePropertyChange(String propertyName, short oldValue, short newValue)
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as a short)newValue
- the old value of the property (as a short)firePropertyChange(java.lang.String, java.lang.Object,
java.lang.Object)
public void firePropertyChange(String propertyName, int oldValue, int newValue)
firePropertyChange
in class Component
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as an int)newValue
- the new value of the property (as an int)firePropertyChange(java.lang.String, java.lang.Object,
java.lang.Object)
public void firePropertyChange(String propertyName, long oldValue, long newValue)
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as a long)newValue
- the new value of the property (as a long)firePropertyChange(java.lang.String, java.lang.Object,
java.lang.Object)
public void firePropertyChange(String propertyName, float oldValue, float newValue)
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as a float)newValue
- the new value of the property (as a float)firePropertyChange(java.lang.String, java.lang.Object,
java.lang.Object)
public void firePropertyChange(String propertyName, double oldValue, double newValue)
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as a double)newValue
- the new value of the property (as a double)firePropertyChange(java.lang.String, java.lang.Object,
java.lang.Object)
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
firePropertyChange
in class Component
propertyName
- the programmatic name of the property
that was changedoldValue
- the old value of the property (as a boolean)newValue
- the property's new valuefirePropertyChange(java.lang.String, java.lang.Object,
java.lang.Object)
public void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
to the listener list.
The listener is registered for all properties.
A PropertyChangeEvent
will get fired in response
to setting a bound property, such as setFont
,
setBackground
, or setForeground
.
Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.
addPropertyChangeListener
in class Container
listener
- the PropertyChangeListener
to be addedComponent.removePropertyChangeListener(java.beans.PropertyChangeListener)
,
Container.addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
PropertyChangeListener
for a specific property.
The listener will be invoked only when a call on
firePropertyChange
names that specific property.
If listener is null
, no exception is thrown and no
action is performed.
addPropertyChangeListener
in class Container
propertyName
- the name of the property to listen onlistener
- the PropertyChangeListener
to be addedContainer.addPropertyChangeListener(java.beans.PropertyChangeListener)
,
Component.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
from the listener list.
This removes a PropertyChangeListener
that was registered
for all properties.
removePropertyChangeListener
in class Component
listener
- the PropertyChangeListener
to be removedComponent.addPropertyChangeListener(java.beans.PropertyChangeListener)
,
Component.getPropertyChangeListeners()
,
Component.removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
PropertyChangeListener
for a specific property.
If listener is null
, no exception is thrown and no
action is performed.
removePropertyChangeListener
in class Component
propertyName
- the name of the property that was listened onlistener
- the PropertyChangeListener
to be removedComponent.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
,
Component.getPropertyChangeListeners(java.lang.String)
,
Component.removePropertyChangeListener(java.beans.PropertyChangeListener)
public PropertyChangeListener[] getPropertyChangeListeners()
PropertyChangeListener
s
added to this Component with addPropertyChangeListener().
getPropertyChangeListeners
in class Component
PropertyChangeListener
s added or
an empty array if no listeners have been addedaddPropertyChangeListener(java.beans.PropertyChangeListener)
,
removePropertyChangeListener(java.beans.PropertyChangeListener)
,
getPropertyChangeListeners(java.lang.String)
,
PropertyChangeSupport.getPropertyChangeListeners()
public PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
getPropertyChangeListeners
in class Component
PropertyChangeListeners
associated with
the named property or an empty array if no listeners have
been addedgetPropertyChangeListeners()
protected void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException
PropertyChangeEvent
to any registered VetoableChangeListeners
.
propertyName
- the name of the property that was listened onoldValue
- the old value of the propertynewValue
- the new value of the property
PropertyVetoException
- when the attempt to set the
property is vetoed by the componentpublic void addVetoableChangeListener(VetoableChangeListener listener)
VetoableChangeListener
to the listener list.
The listener is registered for all properties.
listener
- the VetoableChangeListener
to be addedpublic void removeVetoableChangeListener(VetoableChangeListener listener)
VetoableChangeListener
from the listener list.
This removes a VetoableChangeListener
that was registered
for all properties.
listener
- the VetoableChangeListener
to be removedpublic VetoableChangeListener[] getVetoableChangeListeners()
VetoableChangeListener
s
or an empty
array if no vetoable change listeners are currently registeredaddVetoableChangeListener(java.beans.VetoableChangeListener)
,
removeVetoableChangeListener(java.beans.VetoableChangeListener)
public Container getTopLevelAncestor()
Window
or Applet
),
or null
if this component has not
been added to any container.
Container
that this component is in,
or null
if not in any containerpublic void addAncestorListener(AncestorListener listener)
listener
so that it will receive
AncestorEvents
when it or any of its ancestors
move or are made visible or invisible.
Events are also sent when the component or its ancestors are added
or removed from the containment hierarchy.
listener
- the AncestorListener
to registerAncestorEvent
public void removeAncestorListener(AncestorListener listener)
listener
so that it will no longer receive
AncestorEvents
.
listener
- the AncestorListener
to be removedaddAncestorListener(javax.swing.event.AncestorListener)
public AncestorListener[] getAncestorListeners()
AncestorListener
s
or an empty
array if no ancestor listeners are currently registeredaddAncestorListener(javax.swing.event.AncestorListener)
,
removeAncestorListener(javax.swing.event.AncestorListener)
public EventListener[] getListeners(Class listenerType)
FooListener
s
upon this JComponent
.
FooListener
s are registered using the
addFooListener
method.
You can specify the listenerType
argument
with a class literal,
such as
FooListener.class
.
For example, you can query a
JComponent
c
for its mouse listeners with the following code:
MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));If no such listeners exist, this method returns an empty array.
getListeners
in class Container
listenerType
- the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener
FooListener
s on this component,
or an empty array if no such
listeners have been added
ClassCastException
- if listenerType
doesn't specify a class or interface that implements
java.util.EventListener
getVetoableChangeListeners()
,
getAncestorListeners()
public void addNotify()
KeyboardAction
event listeners.
addNotify
in class Container
registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)
public void removeNotify()
KeyboardAction
s
set up in the the chain of parent components are removed.
removeNotify
in class Container
registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int)
public void repaint(long tm, int x, int y, int width, int height)
repaint
in class Component
tm
- this parameter is not usedx
- the x value of the dirty regiony
- the y value of the dirty regionwidth
- the width of the dirty regionheight
- the height of the dirty regionComponent.isShowing()
,
RepaintManager.addDirtyRegion(javax.swing.JComponent, int, int, int, int)
public void repaint(Rectangle r)
r
- a Rectangle
containing the dirty regionComponent.isShowing()
,
RepaintManager.addDirtyRegion(javax.swing.JComponent, int, int, int, int)
public void revalidate()
Calls invalidate
and then adds this component's
validateRoot
to a list of components that need to be
validated. Validation will occur after all currently pending
events have been dispatched. In other words after this method
is called, the first validateRoot (if any) found when walking
up the containment hierarchy of this component will be validated.
By default, JRootPane
, JScrollPane
,
and JTextField
return true
from isValidateRoot
.
This method will automatically be called on this component
when a property value changes such that size, location, or
internal layout of this component has been affected. This automatic
updating differs from the AWT because programs generally no
longer need to invoke validate
to get the contents of the
GUI to update.
Component.invalidate()
,
Container.validate()
,
isValidateRoot()
,
RepaintManager.addInvalidComponent(javax.swing.JComponent)
public boolean isValidateRoot()
revalidate
calls by
descendants of this component will cause the entire tree
beginning with this root to be validated.
Returns false by default. JScrollPane
overrides
this method and returns true.
revalidate()
,
Component.invalidate()
,
Container.validate()
public boolean isOptimizedDrawingEnabled()
JComponent
subclasses that can't make this
guarantee, such as JLayeredPane
,
should override this method to return false.
public void paintImmediately(int x, int y, int w, int h)
It's rarely necessary to call this method. In most cases it's more efficient to call repaint, which defers the actual painting and can collapse redundant requests into a single paint call. This method is useful if one needs to update the display while the current event is being dispatched.
x
- the x value of the region to be paintedy
- the y value of the region to be paintedw
- the width of the region to be paintedh
- the height of the region to be paintedrepaint(long, int, int, int, int)
public void paintImmediately(Rectangle r)
r
- a Rectangle
containing the region to be paintedpublic void setDoubleBuffered(boolean aFlag)
Component
is buffered and one of its ancestor
is also buffered, the ancestor buffer will be used.
aFlag
- if true, set this component to be double bufferedpublic boolean isDoubleBuffered()
isDoubleBuffered
in class Component
public JRootPane getRootPane()
JRootPane
ancestor for this component.
JRootPane
that contains this component,
or null
if no JRootPane
is foundprotected String paramString()
JComponent
.
This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null
.
paramString
in class Container
JComponent
|
JavaTM 2 Platform Std. Ed. v1.4.1 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.