|
JavaTM 2 Platform Std. Ed. v1.3.1 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | 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:
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. A future release of Swing will provide support for long term persistence.
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), Serialized Form| Inner Class Summary | |
class |
JComponent.AccessibleJComponent
Inner class of JComponent used to provide default support for accessibility. |
| Inner classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
| Inner classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent |
| Field Summary | |
protected AccessibleContext |
accessibleContext
The AccessibleContext associated with this JComponent. |
protected EventListenerList |
listenerList
|
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
|
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 / 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()
overridden to ensure Accessibility support |
void |
enable()
overridden to ensure Accessibility support |
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()
Gets 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. |
boolean |
getAutoscrolls()
Returns true if this component automatically scrolls its contents when dragged (when contained in a component that supports scrolling, like JViewport). |
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. |
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 receiver 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)
Return an array of all the listeners that were added to this JComponent with addXXXListener(), where XXX is the name of the listenerType
argument. |
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()
Returns the next focusable component or null if the focus manager should choose the next focusable component automatically. |
Dimension |
getPreferredSize()
If the preferredSize has been set to a non-null value just returns it. |
KeyStroke[] |
getRegisteredKeyStrokes()
Returns the KeyStrokes that will initiate registered actions. |
JRootPane |
getRootPane()
Returns the JRootPane ancestor for a 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. |
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()
Get the value that indicates whether the input verifier for the current focus owner will be called before this component requests focus. |
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()
Sets the focus on the receiving component if it doesn't already have it. |
boolean |
hasFocus()
Returns true if this Component has the keyboard focus. |
void |
hide()
Deprecated. As of JDK version 1.1, replaced by setVisible(boolean). |
boolean |
isDoubleBuffered()
Returns whether the receiving component should use a buffer to paint. |
boolean |
isFocusCycleRoot()
Override this method and return true if your component is the root of of a component tree with its own focus cycle. |
boolean |
isFocusTraversable()
Identifies whether or not this component can receive the focus. |
static boolean |
isLightweightComponent(Component c)
Returns true if this component is a lightweight, that is, if it doesn't have a native window system peer. |
boolean |
isManagingFocus()
Override this method and return true if your JComponent manages focus. |
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 receiving 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 whether the receiving component can obtain the focus by calling requestFocus. |
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)
This method is 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)
If the UI delegate is non-null, calls its paint method. |
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 receiver. |
void |
printAll(Graphics g)
Invoke this method to print the receiver. |
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 void |
processFocusEvent(FocusEvent e)
Processes focus events occurring on this component by dispatching them to any registered FocusListener objects. |
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 occurring on this component by dispatching them to any registered MouseMotionListener objects. |
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()
Requests the focus for the component that should have the focus by default. |
void |
requestFocus()
Sets focus on the receiving component if isRequestFocusEnabled returns true and the component doesn't already have focus. |
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)
If true this component will automatically scroll its contents when dragged, if contained in a component that supports scrolling, such as JViewport. |
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. |
void |
setDoubleBuffered(boolean aFlag)
Sets whether the receiving 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)
Specifies the next component to get the focus after this one, for example, when the tab key is pressed. |
void |
setOpaque(boolean isOpaque)
If true the component paints every pixel within its bounds. |
void |
setPreferredSize(Dimension preferredSize)
Sets the preferred size of the receiving component. |
void |
setRequestFocusEnabled(boolean aFlag)
Sets whether the receiving component can obtain the focus by calling requestFocus. |
void |
setToolTipText(String text)
Registers the text to display in a tool tip. |
protected void |
setUI(ComponentUI newUI)
Sets the look and feel delegate for this component. |
void |
setVerifyInputWhenFocusTarget(boolean flag)
Set 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(g). |
void |
updateUI()
Resets the UI property to a value from the current look and feel. |
| Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree |
| 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
public static final int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
public static final int WHEN_IN_FOCUSED_WINDOW
public static final int UNDEFINED_CONDITION
public static final String TOOL_TIP_TEXT_KEY
protected AccessibleContext accessibleContext
| Constructor Detail |
public JComponent()
| Method Detail |
public void updateUI()
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)
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;
}
updateUI(),
UIManager.getLookAndFeel(),
UIManager.getUI(javax.swing.JComponent)public String getUIClassID()
UIDefaults.getUI(javax.swing.JComponent)protected Graphics getComponentGraphics(Graphics g)
protected void paintComponent(Graphics g)
paint(java.awt.Graphics)protected void paintChildren(Graphics g)
paint(java.awt.Graphics),
Container.paint(java.awt.Graphics)protected void paintBorder(Graphics g)
paint(java.awt.Graphics),
setBorder(javax.swing.border.Border)public void update(Graphics g)
update in class Containerpaint(java.awt.Graphics),
paintComponent(java.awt.Graphics),
ComponentUIpublic void paint(Graphics g)
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 ContainerpaintComponent(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 receiver.printAll in class Componentprint(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 metioned methods. This method sets the
receivers state such that the double buffer will not be used, eg
painting will be done directly on the passed in Graphics.print in class ContainerprintComponent(java.awt.Graphics),
printBorder(java.awt.Graphics),
printChildren(java.awt.Graphics)protected void printComponent(Graphics g)
paintComponent on the receiver. Override this
if you wish to add special painting behavior when printing.print(java.awt.Graphics)protected void printChildren(Graphics g)
paintChildren on the receiver. Override this if you
wish to print the children differently than painting.print(java.awt.Graphics)protected void printBorder(Graphics g)
paintBorder on the receiver. Overrides this if you
wish to print the border differently that it is painted.print(java.awt.Graphics)public boolean isPaintingTile()
public boolean isFocusCycleRoot()
public boolean isManagingFocus()
public void setNextFocusableComponent(Component aComponent)
public Component getNextFocusableComponent()
public void setRequestFocusEnabled(boolean aFlag)
public boolean isRequestFocusEnabled()
setRequestFocusEnabled(boolean)public void requestFocus()
requestFocus in class Componentjava.awt.ComponentFocusEvent,
Component.addFocusListener(java.awt.event.FocusListener),
Component.processFocusEvent(java.awt.event.FocusEvent),
Component.isFocusTraversable()public void grabFocus()
public void setVerifyInputWhenFocusTarget(boolean flag)
new - value for the verifyInputWhenFocusTarget propertyInputVerifier,
setInputVerifier(javax.swing.InputVerifier),
getInputVerifier(),
getVerifyInputWhenFocusTarget()public boolean getVerifyInputWhenFocusTarget()
InputVerifier,
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()
getPreferredSize in class ContainersetPreferredSize(java.awt.Dimension)public void setMaximumSize(Dimension maximumSize)
getMaximumSize()public Dimension getMaximumSize()
getMaximumSize in class ContainersetMaximumSize(java.awt.Dimension)public void setMinimumSize(Dimension minimumSize)
getMinimumSize()public Dimension getMinimumSize()
getMinimumSize in class ContainersetMinimumSize(java.awt.Dimension)public boolean isMinimumSizeSet()
public boolean isPreferredSizeSet()
public boolean isMaximumSizeSet()
public boolean contains(int x,
int y)
contains in class ComponentComponent.contains(int, int)public void setBorder(Border border)
This is a bound property.
border - the border to be rendered for this componentBorder,
CompoundBorderpublic Border getBorder()
setBorder(javax.swing.border.Border)public Insets getInsets()
getInsets in class ContainersetBorder(javax.swing.border.Border)public Insets getInsets(Insets insets)
insets - the Insets object, which can be reusedgetInsets()public float getAlignmentY()
Container.getAlignmentY to return
the horizontal alignment.getAlignmentY in class ContainersetAlignmentY(float),
Component.getAlignmentY()public void setAlignmentY(float alignmentY)
getAlignmentY()public float getAlignmentX()
Container.getAlignmentX to return
the vertical alignment.getAlignmentX in class ContainersetAlignmentX(float),
Component.getAlignmentX()public void setAlignmentX(float alignmentX)
getAlignmentX()public void setInputVerifier(InputVerifier inputVerifier)
InputVerifierpublic InputVerifier getInputVerifier()
InputVerifierpublic Graphics getGraphics()
getGraphics in class Componentjava.awt.Componentnull
if it has none.Component.paint(java.awt.Graphics)public void setDebugGraphicsOptions(int debugOptions)