All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.awt.Component | +----java.awt.Container | +----com.sun.java.swing.JComponent
Compound Borders
Insets (the space between the edges of the component and the area
it is drawn in) can be specified with a blank border. In addition, many
border styles are available, which can be combined to create compound
borders.
Simple Dialog Construction
The JOptionPane class provides a variety of static methods that you
can invoke to create and display both message dialogs and user-choice
dialogs in a variety of formats. The "message" displayed in the
dialog can be a string, a string-generating object, or an arbitrary
component. You can also replace the choice-buttons with components
you specify for user-selections.
For example, the following line creates a simple message dialog that requires the user's confirmation:
JOptionPane.showMessageDialog(null, "The file will be deleted.");Additional options are described in the JOptionPane class.
Support for Accessibility
Swing has built-in support for developers to make
products that are compatible with Assistive Technologies (for
alternative interfaces like, for example, braille.) All of the Swing
components implement interface Accessible.
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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.
new Rectangle(0, 0, getWidth(), getHeight());and all of its ancestors visible Rectangles.
This method will migrate to java.awt.Component in the next major JDK release
protected ComponentUI uilistenerList
protected EventListenerList listenerListWHEN_FOCUSED
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
public JComponent()
public void updateUI()
public void updateUI() { setUI((SliderUI)UIManager.getUI(this); }
protected void setUI(ComponentUI newUI)
public void setUI(SliderUI newUI) { super.setUI(newUI); }
Additionaly JComponent subclasses must provide a getUI method that returns the correct type, e.g.
public SliderUI getUI() { return (SliderUI)ui; }
public String getUIClassID()
protected Graphics getComponentGraphics(Graphics g)
protected void paintComponent(Graphics g)
protected void paintChildren(Graphics g)
protected void paintBorder(Graphics g)
public void update(Graphics g)
public 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) delegates paint
method should just override paintComponent
.
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()
public void requestFocus()
public void grabFocus()
public void setPreferredSize(Dimension preferredSize)
preferredSize
is null, the UI will
be asked for the preferred size
public Dimension getPreferredSize()
public void setMaximumSize(Dimension maximumSize)
public Dimension getMaximumSize()
public void setMinimumSize(Dimension minimumSize)
public Dimension getMinimumSize()
public boolean contains(int x, int y)
public void setBorder(Border border)
This is a bound property.
public Border getBorder()
public Insets getInsets()
public float getAlignmentY()
public void setAlignmentY(float alignmentY)
public float getAlignmentX()
public void setAlignmentX(float alignmentX)
public Graphics getGraphics()
public void setDebugGraphicsOptions(int debugOptions)
public int getDebugGraphicsOptions()
public void registerKeyboardAction(ActionListener anAction, String aCommand, KeyStroke aKeyStroke, int aCondition)
The aCommand will be set in the delivered event if specified.
The Condition 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.
public void registerKeyboardAction(ActionListener anAction, KeyStroke aKeyStroke, int aCondition)
public void unregisterKeyboardAction(KeyStroke aKeyStroke)
public KeyStroke[] getRegisteredKeyStrokes()
public int getConditionForKeyStroke(KeyStroke aKeyStroke)
public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
public void resetKeyboardActions()
public boolean requestDefaultFocus()
public void setVisible(boolean aFlag)
public boolean isFocusTraversable()
protected void processFocusEvent(FocusEvent e)
protected void processComponentKeyEvent(KeyEvent e)
This 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)
public void setToolTipText(String text)
See How to Use Tool Tips in The Java Tutorial for further documentation.
public String getToolTipText()
public String getToolTipText(MouseEvent event)
public Point getToolTipLocation(MouseEvent event)
event is the MouseEvent that caused the ToolTipManager to
show the tooltip.
createToolTip
public JToolTip createToolTip()
- Returns the instance of 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.
scrollRectToVisible
public void scrollRectToVisible(Rectangle aRect)
- Forwards the scrollRectToVisible() message to the JComponent's
parent. Components that can service the request, such as a JViewport,
override this method and perform the scrolling.
- See Also:
- JViewport
setAutoscrolls
public 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
- See Also:
- JViewport, getAutoscrolls
getAutoscrolls
public boolean getAutoscrolls()
- Returns true if this component automatically scrolls its
contents when dragged, (when contained in a component that supports
scrolling, like JViewport
- See Also:
- JViewport, setAutoscrolls
processMouseMotionEvent
protected void processMouseMotionEvent(MouseEvent e)
- Overrides:
- processMouseMotionEvent in class Component
getAccessibleContext
public AccessibleContext getAccessibleContext()
- Get the AccessibleContext associated with this JComponent
- Returns:
- the AccessibleContext of this JComponent
getClientProperty
public final Object getClientProperty(Object key)
- A convenience method for looking up a property value. It is
equivalent to:
getClientProperties().get(key);
- Returns:
- the value of this property or null
- See Also:
- putClientProperty, getClientProperty
putClientProperty
public final void putClientProperty(Object key,
Object value)
- A convenience method for storing up a property value. It is
equivalent to:
getClientProperties().put(key, value);
If value is null this method will remove the property
This method fires PropertyChangeEvents to notify interested
parties of changes to a client property.
- See Also:
- getClientProperty, getClientProperty
isLightweightComponent
public static boolean isLightweightComponent(Component c)
- Returns true if this component is a lightweight, i.e. if it doesn't
have a native window system peer.
This method will migrate to java.awt.Component in the next major JDK release
- Returns:
- true if this component is a lightweight
reshape
public void reshape(int x,
int y,
int w,
int h)
- Moves and resizes this component.
- Overrides:
- reshape in class Component
- See Also:
- setBounds
setBounds
public void setBounds(Rectangle r)
- Moves and resizes this component.
- Overrides:
- setBounds in class Component
- See Also:
- setBounds
getBounds
public Rectangle getBounds(Rectangle rv)
- Store the bounds of this component into "return value" rv and
return 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.
- Parameters:
- rv - the return value, modified to the components bounds
- Returns:
- rv
getSize
public Dimension getSize(Dimension rv)
- Store the width/height of this component into "return value" rv
and return 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.
- Parameters:
- rv - the return value, modified to the components size
- Returns:
- rv
getLocation
public Point getLocation(Point rv)
- Store the x,y origin of this component into "return value" rv
and return 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.
- Parameters:
- rv - the return value, modified to the components location
- Returns:
- rv
getX
public int getX()
- Return the current x coordinate of the components origin.
This method is preferable to writing component.getBounds().x,
or component.getLocation().x because it doesn't cause any
heap allocations.
This method will migrate to java.awt.Component in the next major JDK release
- Returns:
- the current x coordinate of the components origin.
getY
public int getY()
- Return the current y coordinate of the components origin.
This method is preferable to writing component.getBounds().y,
or component.getLocation().y because it doesn't cause any
heap allocations.
This method will migrate to java.awt.Component in the next major JDK release
- Returns:
- the current y coordinate of the components origin.
getWidth
public int getWidth()
- Return the current width of this component.
This method is preferable to writing component.getBounds().width,
or component.getSize().width because it doesn't cause any
heap allocations.
This method will migrate to java.awt.Component in the next major JDK release
- Returns:
- the current width of this component.
getHeight
public int getHeight()
- Return the current height of this component.
This method is preferable to writing component.getBounds().height,
or component.getSize().height because it doesn't cause any
heap allocations.
This method will migrate to java.awt.Component in the next major JDK release
- Returns:
- the current height of this component.
hasFocus
public boolean hasFocus()
- Returns true if this Component has the keyboard focus.
This method will migrate to java.awt.Component in the next major JDK release
- Returns:
- true if this Component has the keyboard focus.
isOpaque
public boolean isOpaque()
- Returns true if this component is completely opaque.
An opaque component paints every pixel within its
rectangular region. A non-opaque component paints only some of
its pixels, allowing the pixels underneath it to "show through".
A component that does not fully paint its pixels therefore
provides a degree of transparency.
Subclasses that guarantee to always completely paint their contents should
override this method and return true.
This method will migrate to java.awt.Component in the next major JDK release
- Returns:
- true if this component is completely opaque.
- See Also:
- setOpaque
setOpaque
public void setOpaque(boolean isOpaque)
- If true the components background will be filled with the
background color. Otherwise, the background is transparent,
and whatever is underneath will show through.
The default value of this property is false.
This is a JavaBeans bound property.
- See Also:
- isOpaque
computeVisibleRect
public 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. The return value is stored in
visibleRect
- See Also:
- getVisibleRect
getVisibleRect
public Rectangle getVisibleRect()
- Returns the Component's "visible rectangle" - the
intersection of this components visible rectangle:
new Rectangle(0, 0, getWidth(), getHeight());
and all of its ancestors visible Rectangles.
- Returns:
- the visible rectangle
firePropertyChange
protected void firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
- Support for reporting bound property changes. If 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 int:
public void setFoo(int newValue) {
int oldValue = foo;
foo = newValue;
firePropertyChange("foo", oldValue, newValue);
}
This method will migrate to java.awt.Component in the next major JDK release
- Parameters:
- propertyName - The programmatic name of the property that was changed.
- oldValue - The old value of the property.
- newValue - The new value of the property.
- See Also:
- PropertyChangeSupport
firePropertyChange
public void firePropertyChange(String propertyName,
byte oldValue,
byte newValue)
- See Also:
- firePropertyChange
firePropertyChange
public void firePropertyChange(String propertyName,
char oldValue,
char newValue)
- See Also:
- firePropertyChange
firePropertyChange
public void firePropertyChange(String propertyName,
short oldValue,
short newValue)
- See Also:
- firePropertyChange
firePropertyChange
public void firePropertyChange(String propertyName,
int oldValue,
int newValue)
- See Also:
- firePropertyChange
firePropertyChange
public void firePropertyChange(String propertyName,
long oldValue,
long newValue)
- See Also:
- firePropertyChange
firePropertyChange
public void firePropertyChange(String propertyName,
float oldValue,
float newValue)
- See Also:
- firePropertyChange
firePropertyChange
public void firePropertyChange(String propertyName,
double oldValue,
double newValue)
- See Also:
- firePropertyChange
firePropertyChange
public void firePropertyChange(String propertyName,
boolean oldValue,
boolean newValue)
- See Also:
- firePropertyChange
addPropertyChangeListener
public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
- Add a PropertyChangeListener to the listener list.
The listener is registered for all properties.
A PropertyChangeEvent will get fired in response to setting
a bound property, e.g. 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.
This method will migrate to java.awt.Component in the next major JDK release
- Parameters:
- listener - The PropertyChangeListener to be added
removePropertyChangeListener
public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
- Remove a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.
This method will migrate to java.awt.Component in the next major JDK release
- Parameters:
- listener - The PropertyChangeListener to be removed
fireVetoableChange
protected void fireVetoableChange(String propertyName,
Object oldValue,
Object newValue) throws PropertyVetoException
- Support for reporting constrained property changes. This method can be called
when a constrained property has changed and it will send the appropriate
PropertyChangeEvent to any registered VetoableChangeListeners.
This method will migrate to java.awt.Component in the next major JDK release
- Throws: PropertyVetoException
- when the attempt to set the property is vetoed
by the receiver.
addVetoableChangeListener
public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
- Add a VetoableChangeListener to the listener list.
The listener is registered for all properties.
This method will migrate to java.awt.Component in the next major JDK release
- Parameters:
- listener - The VetoableChangeListener to be added
removeVetoableChangeListener
public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
- Remove a VetoableChangeListener from the listener list.
This removes a VetoableChangeListener that was registered
for all properties.
This method will migrate to java.awt.Component in the next major JDK release
- Parameters:
- listener - The VetoableChangeListener to be removed
getTopLevelAncestor
public 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.
- Returns:
- the top-level Container which this component is in.
addAncestorListener
public 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.
Events are also sent when the component or its ancestors are added
or removed from the Component hierarchy
This method will migrate to java.awt.Component in the next major JDK release
- See Also:
- AncestorEvent
removeAncestorListener
public void removeAncestorListener(AncestorListener listener)
- Unregisters listener so that it will no longer receive
AncestorEvents
This method will migrate to java.awt.Component in the next major JDK release
- See Also:
- addAncestorListener
addNotify
public void addNotify()
- Notification to this component that it now has a parent component.
When this method is invoked, the chain of parent components is
set up with KeyboardAction event listeners.
- Overrides:
- addNotify in class Container
- See Also:
- registerKeyboardAction
removeNotify
public void removeNotify()
- Notification to this component that it no longer has a parent component.
When this method is invoked, any KeyboardActions set up in the
the chain of parent components are removed.
- Overrides:
- removeNotify in class Container
- See Also:
- registerKeyboardAction
repaint
public 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. The component will be repainted after all of the
currently pending events have been dispatched.
- Overrides:
- repaint in class Component
- See Also:
- isShowing, addDirtyRegion
repaint
public void repaint(Rectangle r)
- Adds the specified region to the dirty region list if the component
is showing. The component will be repainted after all of the
currently pending events have been dispatched.
- See Also:
- isShowing, addDirtyRegion
revalidate
public void revalidate()
- Support for deferred automatic layout.
Calls invalidate() and then adds this components validateRoot
to a list of components that need to be validated. Validation
will occur after all currently pending events have been dispatched.
By default only JScrollPane.isValidateRoot() returns true. In other
words after this method is called, the first JScrollPane that
contains this component (if any) will be validated.
- See Also:
- invalidate, validate, isValidateRoot, addInvalidComponent
isValidateRoot
public 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. Returns false by default. JScrollPane overrides
this method and returns true.
- Returns:
- false
- See Also:
- revalidate, invalidate, validate
isOptimizedDrawingEnabled
public boolean isOptimizedDrawingEnabled()
- Returns true if this component tiles its children, i.e. if
it can guarantee that the children will not overlap. The
repainting system is substantially more efficient in this
common case. JComponent subclasses that can't make this
guarantee, e.g. JLayeredPane, should override this method
to return false.
- Returns:
- true if this components children don't overlap
paintImmediately
public void paintImmediately(int x,
int y,
int w,
int h)
- Paint the specified region in this component and all of its
descendants that overlap the region, immediately.
It's rarely neccessary 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.
- See Also:
- repaint
paintImmediately
public void paintImmediately(Rectangle r)
- Paint the specified region now.
This method will migrate to java.awt.Component in the next major JDK release
setDoubleBuffered
public void setDoubleBuffered(boolean aFlag)
- Set whether the receiving component should use a buffer to paint.
If set to true, all the drawing from this component will be done
in an offscreen painting buffer. The offscreen painting buffer will
the be copied onto the screen.
Swing's painting system always use a maximum of one double buffer.
If a Component is buffered and one of its ancestor is also buffered,
the ancestor buffer will be used.
isDoubleBuffered
public boolean isDoubleBuffered()
- Return whether the receiving component should use a buffer to paint.
getRootPane
public JRootPane getRootPane()
- Return the receiving component root pane
All Packages Class Hierarchy This Package Previous Next Index