Methods Summary |
---|
void | _paintImmediately(int x, int y, int w, int h)
Graphics g;
Container c;
Rectangle b;
int tmpX, tmpY, tmpWidth, tmpHeight;
int offsetX=0,offsetY=0;
boolean hasBuffer = false;
JComponent bufferedComponent = null;
JComponent paintingComponent = this;
RepaintManager repaintManager = RepaintManager.currentManager(this);
// parent Container's up to Window or Applet. First container is
// the direct parent. Note that in testing it was faster to
// alloc a new Vector vs keeping a stack of them around, and gc
// seemed to have a minimal effect on this.
java.util.List<Component> path = new java.util.ArrayList<Component>(7);
int pIndex = -1;
int pCount = 0;
tmpX = tmpY = tmpWidth = tmpHeight = 0;
Rectangle paintImmediatelyClip = fetchRectangle();
paintImmediatelyClip.x = x;
paintImmediatelyClip.y = y;
paintImmediatelyClip.width = w;
paintImmediatelyClip.height = h;
// System.out.println("1) ************* in _paintImmediately for " + this);
boolean ontop = alwaysOnTop() && isOpaque();
if (ontop) {
SwingUtilities.computeIntersection(0, 0, getWidth(), getHeight(),
paintImmediatelyClip);
if (paintImmediatelyClip.width == 0) {
recycleRectangle(paintImmediatelyClip);
return;
}
}
Component child;
for (c = this, child = null;
c != null && !(c instanceof Window) && !(c instanceof Applet);
child = c, c = c.getParent()) {
JComponent jc = (c instanceof JComponent) ? (JComponent)c :
null;
path.add(c);
if(!ontop && jc != null && !jc.isOptimizedDrawingEnabled()) {
boolean resetPC;
// Children of c may overlap, three possible cases for the
// painting region:
// . Completely obscured by an opaque sibling, in which
// case there is no need to paint.
// . Partially obscured by a sibling: need to start
// painting from c.
// . Otherwise we aren't obscured and thus don't need to
// start painting from parent.
if (c != this) {
if (jc.isPaintingOrigin()) {
resetPC = true;
}
else {
Component[] children = c.getComponents();
int i = 0;
for (; i<children.length; i++) {
if (children[i] == child) break;
}
switch (jc.getObscuredState(i,
paintImmediatelyClip.x,
paintImmediatelyClip.y,
paintImmediatelyClip.width,
paintImmediatelyClip.height)) {
case NOT_OBSCURED:
resetPC = false;
break;
case COMPLETELY_OBSCURED:
recycleRectangle(paintImmediatelyClip);
return;
default:
resetPC = true;
break;
}
}
}
else {
resetPC = false;
}
if (resetPC) {
// Get rid of any buffer since we draw from here and
// we might draw something larger
paintingComponent = jc;
pIndex = pCount;
offsetX = offsetY = 0;
hasBuffer = false;
}
}
pCount++;
// look to see if the parent (and therefor this component)
// is double buffered
if(repaintManager.isDoubleBufferingEnabled() && jc != null &&
jc.isDoubleBuffered()) {
hasBuffer = true;
bufferedComponent = jc;
}
// if we aren't on top, include the parent's clip
if (!ontop) {
int bx = c.getX();
int by = c.getY();
tmpWidth = c.getWidth();
tmpHeight = c.getHeight();
SwingUtilities.computeIntersection(tmpX,tmpY,tmpWidth,tmpHeight,paintImmediatelyClip);
paintImmediatelyClip.x += bx;
paintImmediatelyClip.y += by;
offsetX += bx;
offsetY += by;
}
}
// If the clip width or height is negative, don't bother painting
if(c == null || c.getPeer() == null ||
paintImmediatelyClip.width <= 0 ||
paintImmediatelyClip.height <= 0) {
recycleRectangle(paintImmediatelyClip);
return;
}
paintingComponent.setFlag(IS_REPAINTING, true);
paintImmediatelyClip.x -= offsetX;
paintImmediatelyClip.y -= offsetY;
// Notify the Components that are going to be painted of the
// child component to paint to.
if(paintingComponent != this) {
Component comp;
int i = pIndex;
for(; i > 0 ; i--) {
comp = path.get(i);
if(comp instanceof JComponent) {
((JComponent)comp).setPaintingChild(path.get(i-1));
}
}
}
try {
g = safelyGetGraphics(paintingComponent, c);
try {
if (hasBuffer) {
RepaintManager rm = RepaintManager.currentManager(
bufferedComponent);
rm.beginPaint();
try {
rm.paint(paintingComponent, bufferedComponent, g,
paintImmediatelyClip.x,
paintImmediatelyClip.y,
paintImmediatelyClip.width,
paintImmediatelyClip.height);
} finally {
rm.endPaint();
}
}
else {
g.setClip(paintImmediatelyClip.x,paintImmediatelyClip.y,
paintImmediatelyClip.width,paintImmediatelyClip.height);
paintingComponent.paint(g);
}
} finally {
g.dispose();
}
}
finally {
// Reset the painting child for the parent components.
if(paintingComponent != this) {
Component comp;
int i = pIndex;
for(; i > 0 ; i--) {
comp = path.get(i);
if(comp instanceof JComponent) {
((JComponent)comp).setPaintingChild(null);
}
}
}
paintingComponent.setFlag(IS_REPAINTING, false);
}
recycleRectangle(paintImmediatelyClip);
|
public void | addAncestorListener(javax.swing.event.AncestorListener listener)Registers 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.
AncestorNotifier ancestorNotifier = getAncestorNotifier();
if (ancestorNotifier == null) {
ancestorNotifier = new AncestorNotifier(this);
putClientProperty(ANCESTOR_NOTIFIER_KEY, ancestorNotifier);
}
ancestorNotifier.addAncestorListener(listener);
|
public void | addNotify()Notifies 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.
super.addNotify();
firePropertyChange("ancestor", null, getParent());
registerWithKeyboardManager(false);
registerNextFocusableComponent();
|
public synchronized void | addVetoableChangeListener(java.beans.VetoableChangeListener listener)Adds a VetoableChangeListener to the listener list.
The listener is registered for all properties.
if (vetoableChangeSupport == null) {
vetoableChangeSupport = new java.beans.VetoableChangeSupport(this);
}
vetoableChangeSupport.addVetoableChangeListener(listener);
|
private void | adjustPaintFlags()
JComponent jparent = null;
Container parent;
for(parent = getParent() ; parent != null ; parent =
parent.getParent()) {
if(parent instanceof JComponent) {
jparent = (JComponent) parent;
if(jparent.getFlag(ANCESTOR_USING_BUFFER))
setFlag(ANCESTOR_USING_BUFFER, true);
if(jparent.getFlag(IS_PAINTING_TILE))
setFlag(IS_PAINTING_TILE, true);
if(jparent.getFlag(IS_PRINTING))
setFlag(IS_PRINTING, true);
if(jparent.getFlag(IS_PRINTING_ALL))
setFlag(IS_PRINTING_ALL, true);
break;
}
}
|
boolean | alwaysOnTop()Returns whether this component should be guaranteed to be on top.
For example, it would make no sense for Menu s to pop up
under another component, so they would always return true.
Most components will want to return false, hence that is the default.
return false;
|
boolean | checkIfChildObscuredBySibling()Returns true, which implies that before checking if a child should
be painted it is first check that the child is not obscured by another
sibling. This is only checked if isOptimizedDrawingEnabled
returns false.
return true;
|
void | clientPropertyChanged(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
|
void | compWriteObjectNotify()This is called from Component by way of reflection. Do NOT change
the name unless you change the code in Component as well.
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, (byte)(count + 1));
if (count != 0) {
return;
}
if (ui != null) {
ui.uninstallUI(this);
}
/* JTableHeader is in a separate package, which prevents it from
* being able to override this package-private method the way the
* other components can. We don't want to make this method protected
* because it would introduce public-api for a less-than-desirable
* serialization scheme, so we compromise with this 'instanceof' hack
* for now.
*/
if (getToolTipText() != null ||
this instanceof javax.swing.table.JTableHeader) {
ToolTipManager.sharedInstance().unregisterComponent(JComponent.this);
}
|
void | componentInputMapChanged(javax.swing.ComponentInputMap inputMap)Invoked from ComponentInputMap when its bindings change.
If inputMap is the current windowInputMap
(or a parent of the window InputMap )
the KeyboardManager is notified of the new bindings.
InputMap km = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
while (km != inputMap && km != null) {
km = (ComponentInputMap)km.getParent();
}
if (km != null) {
registerWithKeyboardManager(false);
}
|
static final void | computeVisibleRect(java.awt.Component c, java.awt.Rectangle visibleRect)Returns the Component 's "visible rect rectangle" - the
intersection of the visible rectangles for the component c
and all of its ancestors. The return value is stored in
visibleRect .
Container p = c.getParent();
Rectangle bounds = c.getBounds();
if (p == null || p instanceof Window || p instanceof Applet) {
visibleRect.setBounds(0, 0, bounds.width, bounds.height);
} else {
computeVisibleRect(p, visibleRect);
visibleRect.x -= bounds.x;
visibleRect.y -= bounds.y;
SwingUtilities.computeIntersection(0,0,bounds.width,bounds.height,visibleRect);
}
|
public void | computeVisibleRect(java.awt.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 .
computeVisibleRect(this, visibleRect);
|
public 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.
return (ui != null) ? ui.contains(this, x, y) : super.contains(x, y);
|
public javax.swing.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.
JToolTip tip = new JToolTip();
tip.setComponent(this);
return tip;
|
private void | deregisterNextFocusableComponent()
Component nextFocusableComponent = getNextFocusableComponent();
if (nextFocusableComponent == null) {
return;
}
Container nearestRoot =
(isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
if (nearestRoot == null) {
return;
}
FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
if (policy instanceof LegacyGlueFocusTraversalPolicy) {
((LegacyGlueFocusTraversalPolicy)policy).
unsetNextFocusableComponent(this, nextFocusableComponent);
}
|
public void | disable()
if (isEnabled() != false) {
super.disable();
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
AccessibleState.ENABLED, null);
}
}
|
void | dndDone()Called to indicate to this component that DnD is done.
Needed by JTree .
|
javax.swing.TransferHandler$DropLocation | dropLocationForPoint(java.awt.Point p)Calculates a custom drop location for this type of component,
representing where a drop at the given point should insert data.
null is returned if this component doesn't calculate
custom drop locations. In this case, TransferHandler
will provide a default DropLocation containing just
the point.
return null;
|
public void | enable()
/*
* --- Accessibility Support ---
*/
if (isEnabled() != true) {
super.enable();
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
null, AccessibleState.ENABLED);
}
}
|
private static java.awt.Rectangle | fetchRectangle()
synchronized(tempRectangles) {
Rectangle rect;
int size = tempRectangles.size();
if (size > 0) {
rect = (Rectangle)tempRectangles.remove(size - 1);
}
else {
rect = new Rectangle(0, 0, 0, 0);
}
return rect;
}
|
public void | firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)Support for reporting bound property changes for boolean properties.
This method can be called when a bound property has changed and it will
send the appropriate PropertyChangeEvent to any registered
PropertyChangeListeners.
super.firePropertyChange(propertyName, oldValue, newValue);
|
public void | firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)Support for reporting bound property changes for integer properties.
This method can be called when a bound property has changed and it will
send the appropriate PropertyChangeEvent to any registered
PropertyChangeListeners.
super.firePropertyChange(propertyName, oldValue, newValue);
|
public void | firePropertyChange(java.lang.String propertyName, char oldValue, char newValue)
super.firePropertyChange(propertyName, oldValue, newValue);
|
protected void | fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)Supports 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 .
if (vetoableChangeSupport == null) {
return;
}
vetoableChangeSupport.fireVetoableChange(propertyName, oldValue, newValue);
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Returns the 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.
return accessibleContext;
|
public java.awt.event.ActionListener | getActionForKeyStroke(javax.swing.KeyStroke aKeyStroke)Returns the object that will perform the action registered for a
given keystroke.
ActionMap am = getActionMap(false);
if (am == null) {
return null;
}
for (int counter = 0; counter < 3; counter++) {
InputMap inputMap = getInputMap(counter, false);
if (inputMap != null) {
Object actionBinding = inputMap.get(aKeyStroke);
if (actionBinding != null) {
Action action = am.get(actionBinding);
if (action instanceof ActionStandin) {
return ((ActionStandin)action).actionListener;
}
return action;
}
}
}
return null;
|
public final javax.swing.ActionMap | getActionMap()Returns the 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.
return getActionMap(true);
|
final javax.swing.ActionMap | getActionMap(boolean create)Finds and returns the appropriate ActionMap .
if (getFlag(ACTIONMAP_CREATED)) {
return actionMap;
}
// Hasn't been created.
if (create) {
ActionMap am = new ActionMap();
setActionMap(am);
return am;
}
return null;
|
public float | getAlignmentX()Overrides Container.getAlignmentX to return
the vertical alignment.
if (isAlignmentXSet) {
return alignmentX;
}
return super.getAlignmentX();
|
public float | getAlignmentY()Overrides Container.getAlignmentY to return
the horizontal alignment.
if (isAlignmentYSet) {
return alignmentY;
}
return super.getAlignmentY();
|
public javax.swing.event.AncestorListener[] | getAncestorListeners()Returns an array of all the ancestor listeners
registered on this component.
AncestorNotifier ancestorNotifier = getAncestorNotifier();
if (ancestorNotifier == null) {
return new AncestorListener[0];
}
return ancestorNotifier.getAncestorListeners();
|
private javax.swing.AncestorNotifier | getAncestorNotifier()
return (AncestorNotifier)getClientProperty(ANCESTOR_NOTIFIER_KEY);
|
public boolean | getAutoscrolls()Gets the autoscrolls property.
return autoscrolls;
|
public int | getBaseline(int width, int height)Returns the baseline. The baseline is measured from the top of
the component. This method is primarily meant for
LayoutManager s to align components along their
baseline. A return value less than 0 indicates this component
does not have a reasonable baseline and that
LayoutManager s should not align this component on
its baseline.
This method calls into the ComponentUI method of the
same name. If this component does not have a ComponentUI
-1 will be returned. If a value >= 0 is
returned, then the component has a valid baseline for any
size >= the minimum size and getBaselineResizeBehavior
can be used to determine how the baseline changes with size.
// check size.
super.getBaseline(width, height);
if (ui != null) {
return ui.getBaseline(this, width, height);
}
return -1;
|
public BaselineResizeBehavior | getBaselineResizeBehavior()Returns an enum indicating how the baseline of the component
changes as the size changes. This method is primarily meant for
layout managers and GUI builders.
This method calls into the ComponentUI method of
the same name. If this component does not have a
ComponentUI
BaselineResizeBehavior.OTHER will be
returned. Subclasses should
never return null ; if the baseline can not be
calculated return BaselineResizeBehavior.OTHER . Callers
should first ask for the baseline using
getBaseline and if a value >= 0 is returned use
this method. It is acceptable for this method to return a
value other than BaselineResizeBehavior.OTHER even if
getBaseline returns a value less than 0.
if (ui != null) {
return ui.getBaselineResizeBehavior(this);
}
return BaselineResizeBehavior.OTHER;
|
public javax.swing.border.Border | getBorder()Returns the border of this component or null if no
border is currently set.
return border;
|
public java.awt.Rectangle | getBounds(java.awt.Rectangle rv)Stores the bounds of this component into "return value"
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.
if (rv == null) {
return new Rectangle(getX(), getY(), getWidth(), getHeight());
}
else {
rv.setBounds(getX(), getY(), getWidth(), getHeight());
return rv;
}
|
private javax.swing.ArrayTable | getClientProperties()Returns an ArrayTable used for
key/value "client properties" for this component. If the
clientProperties table doesn't exist, an empty one
will be created.
if (clientProperties == null) {
clientProperties = new ArrayTable();
}
return clientProperties;
|
public final java.lang.Object | getClientProperty(java.lang.Object key)Returns the value of the property with the specified key. Only
properties added with putClientProperty will return
a non-null value.
if (key == SwingUtilities2.AA_TEXT_PROPERTY_KEY) {
return aaTextInfo;
} else if (key == SwingUtilities2.COMPONENT_UI_PROPERTY_KEY) {
return ui;
}
if(clientProperties == null) {
return null;
} else {
synchronized(clientProperties) {
return clientProperties.get(key);
}
}
|
protected java.awt.Graphics | getComponentGraphics(java.awt.Graphics g)Returns the graphics object used to paint this component.
If DebugGraphics is turned on we create a new
DebugGraphics object if necessary.
Otherwise we just configure the
specified graphics object's foreground and font.
Graphics componentGraphics = g;
if (ui != null && DEBUG_GRAPHICS_LOADED) {
if ((DebugGraphics.debugComponentCount() != 0) &&
(shouldDebugGraphics() != 0) &&
!(g instanceof DebugGraphics)) {
componentGraphics = new DebugGraphics(g,this);
}
}
componentGraphics.setColor(getForeground());
componentGraphics.setFont(getFont());
return componentGraphics;
|
public javax.swing.JPopupMenu | getComponentPopupMenu()Returns JPopupMenu that assigned for this component.
If this component does not have a JPopupMenu assigned
to it and getInheritsPopupMenu is true, this
will return getParent().getComponentPopupMenu() (assuming
the parent is valid.)
if(!getInheritsPopupMenu()) {
return popupMenu;
}
if(popupMenu == null) {
// Search parents for its popup
Container parent = getParent();
while (parent != null) {
if(parent instanceof JComponent) {
return ((JComponent)parent).getComponentPopupMenu();
}
if(parent instanceof Window ||
parent instanceof Applet) {
// Reached toplevel, break and return null
break;
}
parent = parent.getParent();
}
return null;
}
return popupMenu;
|
public int | getConditionForKeyStroke(javax.swing.KeyStroke aKeyStroke)Returns the condition that determines whether a registered action
occurs in response to the specified keystroke.
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.
for (int counter = 0; counter < 3; counter++) {
InputMap inputMap = getInputMap(counter, false);
if (inputMap != null && inputMap.get(aKeyStroke) != null) {
return counter;
}
}
return UNDEFINED_CONDITION;
|
boolean | getCreatedDoubleBuffer()Returns true if the RepaintManager
created the double buffer image from the component.
return getFlag(CREATED_DOUBLE_BUFFER);
|
public int | getDebugGraphicsOptions()Returns the state of graphics debugging.
return DebugGraphics.getDebugOptions(this);
|
public static java.util.Locale | getDefaultLocale()Returns the default locale used to initialize each JComponent's
locale property upon creation.
The default locale has "AppContext" scope so that applets (and
potentially multiple lightweight applications running in a single VM)
can have their own setting. An applet can safely alter its default
locale because it will have no affect on other applets (or the browser).
Locale l = (Locale) SwingUtilities.appContextGet(defaultLocale);
if( l == null ) {
//REMIND(bcb) choosing the default value is more complicated
//than this.
l = Locale.getDefault();
JComponent.setDefaultLocale( l );
}
return l;
|
private boolean | getFlag(int aFlag)
int mask = (1 << aFlag);
return ((flags & mask) == mask);
|
public java.awt.FontMetrics | getFontMetrics(java.awt.Font font)Gets the FontMetrics for the specified Font .
return SwingUtilities2.getFontMetrics(this, font);
|
public java.awt.Graphics | getGraphics()Returns this component's graphics context, which lets you draw
on a component. Use this method to get a Graphics object and
then invoke operations on that object to draw on the component.
if (DEBUG_GRAPHICS_LOADED && shouldDebugGraphics() != 0) {
DebugGraphics graphics = new DebugGraphics(super.getGraphics(),
this);
return graphics;
}
return super.getGraphics();
|
static void | getGraphicsInvoked(java.awt.Component root)
if (!JComponent.isComponentObtainingGraphicsFrom(root)) {
JRootPane rootPane = ((RootPaneContainer)root).getRootPane();
if (rootPane != null) {
rootPane.disableTrueDoubleBuffering();
}
}
|
public int | getHeight()Returns 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. return super.getHeight();
|
public boolean | getInheritsPopupMenu()Returns true if the JPopupMenu should be inherited from the parent.
return getFlag(INHERITS_POPUP_MENU);
|
public final javax.swing.InputMap | getInputMap(int condition)Returns the InputMap that is used during
condition .
return getInputMap(condition, true);
|
public final javax.swing.InputMap | getInputMap()Returns the InputMap that is used when the
component has focus.
This is convenience method for getInputMap(WHEN_FOCUSED) .
return getInputMap(WHEN_FOCUSED, true);
|
final javax.swing.InputMap | getInputMap(int condition, boolean create)Returns the InputMap to use for condition
condition . If the InputMap hasn't
been created, and create is
true, it will be created.
switch (condition) {
case WHEN_FOCUSED:
if (getFlag(FOCUS_INPUTMAP_CREATED)) {
return focusInputMap;
}
// Hasn't been created yet.
if (create) {
InputMap km = new InputMap();
setInputMap(condition, km);
return km;
}
break;
case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
if (getFlag(ANCESTOR_INPUTMAP_CREATED)) {
return ancestorInputMap;
}
// Hasn't been created yet.
if (create) {
InputMap km = new InputMap();
setInputMap(condition, km);
return km;
}
break;
case WHEN_IN_FOCUSED_WINDOW:
if (getFlag(WIF_INPUTMAP_CREATED)) {
return windowInputMap;
}
// Hasn't been created yet.
if (create) {
ComponentInputMap km = new ComponentInputMap(this);
setInputMap(condition, km);
return km;
}
break;
default:
throw new IllegalArgumentException("condition must be one of JComponent.WHEN_IN_FOCUSED_WINDOW, JComponent.WHEN_FOCUSED or JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT");
}
return null;
|
public javax.swing.InputVerifier | getInputVerifier()Returns the input verifier for this component.
return (InputVerifier)getClientProperty(INPUT_VERIFIER_KEY);
|
public java.awt.Insets | getInsets()If a border has been set on this component, returns the
border's insets; otherwise calls super.getInsets .
if (border != null) {
return border.getBorderInsets(this);
}
return super.getInsets();
|
public java.awt.Insets | getInsets(java.awt.Insets insets)Returns an 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.
if (insets == null) {
insets = new Insets(0, 0, 0, 0);
}
if (border != null) {
if (border instanceof AbstractBorder) {
return ((AbstractBorder)border).getBorderInsets(this, insets);
} else {
// Can't reuse border insets because the Border interface
// can't be enhanced.
return border.getBorderInsets(this);
}
} else {
// super.getInsets() always returns an Insets object with
// all of its value zeroed. No need for a new object here.
insets.left = insets.top = insets.right = insets.bottom = 0;
return insets;
}
|
public T[] | getListeners(java.lang.Class listenerType)Returns an array of all the objects currently registered
as 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.
T[] result;
if (listenerType == AncestorListener.class) {
// AncestorListeners are handled by the AncestorNotifier
result = (T[])getAncestorListeners();
}
else if (listenerType == VetoableChangeListener.class) {
// VetoableChangeListeners are handled by VetoableChangeSupport
result = (T[])getVetoableChangeListeners();
}
else if (listenerType == PropertyChangeListener.class) {
// PropertyChangeListeners are handled by PropertyChangeSupport
result = (T[])getPropertyChangeListeners();
}
else {
result = (T[])listenerList.getListeners(listenerType);
}
if (result.length == 0) {
return super.getListeners(listenerType);
}
return result;
|
public java.awt.Point | getLocation(java.awt.Point rv)Stores the x,y origin of this component into "return value"
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.
if (rv == null) {
return new Point(getX(), getY());
}
else {
rv.setLocation(getX(), getY());
return rv;
}
|
static java.util.Set | getManagingFocusBackwardTraversalKeys()Returns the Set of KeyStroke s to use if the component
is managing focus for backward focus traversal.
synchronized(JComponent.class) {
if (managingFocusBackwardTraversalKeys == null) {
managingFocusBackwardTraversalKeys = new HashSet<KeyStroke>(1);
managingFocusBackwardTraversalKeys.add(
KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
InputEvent.SHIFT_MASK |
InputEvent.CTRL_MASK));
}
}
return managingFocusBackwardTraversalKeys;
|
static java.util.Set | getManagingFocusForwardTraversalKeys()Returns the Set of KeyStroke s to use if the component
is managing focus for forward focus traversal.
synchronized(JComponent.class) {
if (managingFocusForwardTraversalKeys == null) {
managingFocusForwardTraversalKeys = new HashSet<KeyStroke>(1);
managingFocusForwardTraversalKeys.add(
KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
InputEvent.CTRL_MASK));
}
}
return managingFocusForwardTraversalKeys;
|
public java.awt.Dimension | getMaximumSize()If the maximum size has been set to a non-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.
if (isMaximumSizeSet()) {
return super.getMaximumSize();
}
Dimension size = null;
if (ui != null) {
size = ui.getMaximumSize(this);
}
return (size != null) ? size : super.getMaximumSize();
|
public java.awt.Dimension | getMinimumSize()If the minimum size has been set to a non-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.
if (isMinimumSizeSet()) {
return super.getMinimumSize();
}
Dimension size = null;
if (ui != null) {
size = ui.getMinimumSize(this);
}
return (size != null) ? size : super.getMinimumSize();
|
public java.awt.Component | getNextFocusableComponent()In release 1.4, the focus subsystem was rearchitected.
For more information, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
Returns the Component set by a prior call to
setNextFocusableComponent(Component) on this
JComponent .
return (Component)getClientProperty(NEXT_FOCUS);
|
private int | getObscuredState(int compIndex, int x, int y, int width, int height)Returns whether or not the region of the specified component is
obscured by a sibling.
int retValue = NOT_OBSCURED;
Rectangle tmpRect = fetchRectangle();
for (int i = compIndex - 1 ; i >= 0 ; i--) {
Component sibling = getComponent(i);
if (!sibling.isVisible()) {
continue;
}
Rectangle siblingRect;
boolean opaque;
if (sibling instanceof JComponent) {
opaque = ((JComponent)sibling).isOpaque();
if (!opaque) {
if (retValue == PARTIALLY_OBSCURED) {
continue;
}
}
}
else {
opaque = true;
}
siblingRect = sibling.getBounds(tmpRect);
if (opaque && x >= siblingRect.x && (x + width) <=
(siblingRect.x + siblingRect.width) &&
y >= siblingRect.y && (y + height) <=
(siblingRect.y + siblingRect.height)) {
recycleRectangle(tmpRect);
return COMPLETELY_OBSCURED;
}
else if (retValue == NOT_OBSCURED &&
!((x + width <= siblingRect.x) ||
(y + height <= siblingRect.y) ||
(x >= siblingRect.x + siblingRect.width) ||
(y >= siblingRect.y + siblingRect.height))) {
retValue = PARTIALLY_OBSCURED;
}
}
recycleRectangle(tmpRect);
return retValue;
|
public java.awt.Point | getPopupLocation(java.awt.event.MouseEvent event)Returns the preferred location to display the popup menu in this
component's coordinate system. It is up to the look and feel to
honor this property, some may choose to ignore it.
If {@code null}, the look and feel will choose a suitable location.
return null;
|
public java.awt.Dimension | getPreferredSize()If the 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.
if (isPreferredSizeSet()) {
return super.getPreferredSize();
}
Dimension size = null;
if (ui != null) {
size = ui.getPreferredSize(this);
}
return (size != null) ? size : super.getPreferredSize();
|
public javax.swing.KeyStroke[] | getRegisteredKeyStrokes()Returns the KeyStrokes that will initiate
registered actions.
int[] counts = new int[3];
KeyStroke[][] strokes = new KeyStroke[3][];
for (int counter = 0; counter < 3; counter++) {
InputMap km = getInputMap(counter, false);
strokes[counter] = (km != null) ? km.allKeys() : null;
counts[counter] = (strokes[counter] != null) ?
strokes[counter].length : 0;
}
KeyStroke[] retValue = new KeyStroke[counts[0] + counts[1] +
counts[2]];
for (int counter = 0, last = 0; counter < 3; counter++) {
if (counts[counter] > 0) {
System.arraycopy(strokes[counter], 0, retValue, last,
counts[counter]);
last += counts[counter];
}
}
return retValue;
|
public javax.swing.JRootPane | getRootPane()Returns the JRootPane ancestor for this component.
return SwingUtilities.getRootPane(this);
|
public java.awt.Dimension | getSize(java.awt.Dimension rv)Stores the width/height of this component into "return value"
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.
if (rv == null) {
return new Dimension(getWidth(), getHeight());
}
else {
rv.setSize(getWidth(), getHeight());
return rv;
}
|
public java.awt.Point | getToolTipLocation(java.awt.event.MouseEvent event)Returns the tooltip location in this component's coordinate system.
If null is returned, Swing will choose a location.
The default implementation returns null .
return null;
|
public java.lang.String | getToolTipText()Returns the tooltip string that has been set with
setToolTipText .
return (String)getClientProperty(TOOL_TIP_TEXT_KEY);
|
public java.lang.String | getToolTipText(java.awt.event.MouseEvent event)Returns the string to be used as the tooltip for event.
By default this returns any string set using
setToolTipText . If a component provides
more extensive API to support differing tooltips at different locations,
this method should be overridden.
return getToolTipText();
|
public java.awt.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.
for(Container p = this; p != null; p = p.getParent()) {
if(p instanceof Window || p instanceof Applet) {
return p;
}
}
return null;
|
public javax.swing.TransferHandler | getTransferHandler()Gets the transferHandler property.
return (TransferHandler)getClientProperty(TRANSFER_HANDLER_KEY);
|
public java.lang.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. 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.
return uiClassID;
|
public boolean | getVerifyInputWhenFocusTarget()Returns the value that indicates whether the input verifier for the
current focus owner will be called before this component requests
focus.
return verifyInputWhenFocusTarget;
|
public synchronized java.beans.VetoableChangeListener[] | getVetoableChangeListeners()Returns an array of all the vetoable change listeners
registered on this component.
if (vetoableChangeSupport == null) {
return new VetoableChangeListener[0];
}
return vetoableChangeSupport.getVetoableChangeListeners();
|
public java.awt.Rectangle | getVisibleRect()Returns the Component 's "visible rectangle" - the
intersection of this component's visible rectangle,
new Rectangle(0, 0, getWidth(), getHeight()) ,
and all of its ancestors' visible rectangles.
Rectangle visibleRect = new Rectangle();
computeVisibleRect(visibleRect);
return visibleRect;
|
public int | getWidth()Returns 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. return super.getWidth();
|
static byte | getWriteObjCounter(javax.swing.JComponent comp)
return (byte)((comp.flags >> WRITE_OBJ_COUNTER_FIRST) & 0xFF);
|
public int | getX()Returns the current x coordinate of the component's origin.
This method is preferable to writing
component.getBounds().x , or
component.getLocation().x because it doesn't cause any
heap allocations. return super.getX();
|
public int | getY()Returns the current y coordinate of the component's origin.
This method is preferable to writing
component.getBounds().y , or
component.getLocation().y because it doesn't cause any
heap allocations. return super.getY();
|
public void | grabFocus()Requests that this Component get the input focus, and that this
Component's top-level ancestor become the focused Window. This component
must be displayable, visible, and focusable for the request to be
granted.
This method is intended for use by focus implementations. Client code
should not use this method; instead, it should use
requestFocusInWindow() .
requestFocus();
|
private static boolean | isComponentObtainingGraphicsFrom(java.awt.Component c)Returns true if {@code c} is the component the graphics is being
requested of. This is intended for use when getGraphics is invoked.
synchronized(componentObtainingGraphicsFromLock) {
return (componentObtainingGraphicsFrom == c);
}
|
public boolean | isDoubleBuffered()Returns whether this component should use a buffer to paint.
return getFlag(IS_DOUBLE_BUFFERED);
|
public static boolean | isLightweightComponent(java.awt.Component c)Returns true if this component is lightweight, that is, if it doesn't
have a native window system peer.
return c.getPeer() instanceof LightweightPeer;
|
public boolean | isManagingFocus()In release 1.4, the focus subsystem was rearchitected.
For more information, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
Changes this 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.
return false;
|
public boolean | isOpaque()Returns true if this component is completely opaque.
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.
return getFlag(IS_OPAQUE);
|
public boolean | isOptimizedDrawingEnabled()Returns true if this component tiles its children -- that is, 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, such as JLayeredPane ,
should override this method to return false.
return true;
|
boolean | isPainting()Returns true if this component, or any of its ancestors, are in
the processing of painting.
Container component = this;
while (component != null) {
if (component instanceof JComponent &&
((JComponent)component).getFlag(ANCESTOR_USING_BUFFER)) {
return true;
}
component = component.getParent();
}
return false;
|
public final boolean | isPaintingForPrint()Returns true if the current painting operation on this
component is part of a print operation. This method is
useful when you want to customize what you print versus what you show
on the screen.
You can detect changes in the value of this property by listening for
property change events on this component with name
"paintingForPrint" .
Note: This method provides complimentary functionality to that provided
by other high level Swing printing APIs. However, it deals strictly with
painting and should not be confused as providing information on higher
level print processes. For example, a {@link javax.swing.JTable#print()}
operation doesn't necessarily result in a continuous rendering of the
full component, and the return value of this method can change multiple
times during that operation. It is even possible for the component to be
painted to the screen while the printing process is ongoing. In such a
case, the return value of this method is true when, and only
when, the table is being painted as part of the printing process.
return getFlag(IS_PRINTING);
|
boolean | isPaintingOrigin()Returns true if a paint triggered on a child component should cause
painting to originate from this Component, or one of its ancestors.
return false;
|
public boolean | isPaintingTile()Returns true if the component is currently painting a tile.
If this method returns true, paint will be called again for another
tile. This method returns false if you are not painting a tile or
if the last tile is painted.
Use this method to keep some state you might need between tiles.
return getFlag(IS_PAINTING_TILE);
|
public boolean | isRequestFocusEnabled()Returns true if this JComponent should
get focus; otherwise returns false .
Please see
How to Use the Focus Subsystem,
a section in The Java Tutorial,
for more information.
return !getFlag(REQUEST_FOCUS_DISABLED);
|
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.
return false;
|
public void | paint(java.awt.Graphics g)Invoked by Swing to draw components.
Applications should not invoke 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 .
boolean shouldClearPaintFlags = false;
if ((getWidth() <= 0) || (getHeight() <= 0)) {
return;
}
Graphics componentGraphics = getComponentGraphics(g);
Graphics co = componentGraphics.create();
try {
RepaintManager repaintManager = RepaintManager.currentManager(this);
Rectangle clipRect = co.getClipBounds();
int clipX;
int clipY;
int clipW;
int clipH;
if (clipRect == null) {
clipX = clipY = 0;
clipW = getWidth();
clipH = getHeight();
}
else {
clipX = clipRect.x;
clipY = clipRect.y;
clipW = clipRect.width;
clipH = clipRect.height;
}
if(clipW > getWidth()) {
clipW = getWidth();
}
if(clipH > getHeight()) {
clipH = getHeight();
}
if(getParent() != null && !(getParent() instanceof JComponent)) {
adjustPaintFlags();
shouldClearPaintFlags = true;
}
int bw,bh;
boolean printing = getFlag(IS_PRINTING);
if(!printing && repaintManager.isDoubleBufferingEnabled() &&
!getFlag(ANCESTOR_USING_BUFFER) && isDoubleBuffered()) {
repaintManager.beginPaint();
try {
repaintManager.paint(this, this, co, clipX, clipY, clipW,
clipH);
} finally {
repaintManager.endPaint();
}
}
else {
// Will ocassionaly happen in 1.2, especially when printing.
if (clipRect == null) {
co.setClip(clipX, clipY, clipW, clipH);
}
if (!rectangleIsObscured(clipX,clipY,clipW,clipH)) {
if (!printing) {
paintComponent(co);
paintBorder(co);
}
else {
printComponent(co);
printBorder(co);
}
}
if (!printing) {
paintChildren(co);
}
else {
printChildren(co);
}
}
} finally {
co.dispose();
if(shouldClearPaintFlags) {
setFlag(ANCESTOR_USING_BUFFER,false);
setFlag(IS_PAINTING_TILE,false);
setFlag(IS_PRINTING,false);
setFlag(IS_PRINTING_ALL,false);
}
}
|
protected void | paintBorder(java.awt.Graphics g)Paints the component's border.
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.
Border border = getBorder();
if (border != null) {
border.paintBorder(this, g, 0, 0, getWidth(), getHeight());
}
|
protected void | paintChildren(java.awt.Graphics g)Paints this component's children.
If 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.
boolean isJComponent;
Graphics sg = g;
synchronized(getTreeLock()) {
int i = getComponentCount() - 1;
if (i < 0) {
return;
}
// If we are only to paint to a specific child, determine
// its index.
if (paintingChild != null &&
(paintingChild instanceof JComponent) &&
((JComponent)paintingChild).isOpaque()) {
for (; i >= 0; i--) {
if (getComponent(i) == paintingChild){
break;
}
}
}
Rectangle tmpRect = fetchRectangle();
boolean checkSiblings = (!isOptimizedDrawingEnabled() &&
checkIfChildObscuredBySibling());
Rectangle clipBounds = null;
if (checkSiblings) {
clipBounds = sg.getClipBounds();
if (clipBounds == null) {
clipBounds = new Rectangle(0, 0, getWidth(),
getHeight());
}
}
boolean printing = getFlag(IS_PRINTING);
for (; i >= 0 ; i--) {
Component comp = getComponent(i);
isJComponent = (comp instanceof JComponent);
if (comp != null &&
(isJComponent || isLightweightComponent(comp)) &&
(comp.isVisible() == true)) {
Rectangle cr;
cr = comp.getBounds(tmpRect);
boolean hitClip = g.hitClip(cr.x, cr.y, cr.width,
cr.height);
if (hitClip) {
if (checkSiblings && i > 0) {
int x = cr.x;
int y = cr.y;
int width = cr.width;
int height = cr.height;
SwingUtilities.computeIntersection
(clipBounds.x, clipBounds.y,
clipBounds.width, clipBounds.height, cr);
if(getObscuredState(i, cr.x, cr.y, cr.width,
cr.height) == COMPLETELY_OBSCURED) {
continue;
}
cr.x = x;
cr.y = y;
cr.width = width;
cr.height = height;
}
Graphics cg = sg.create(cr.x, cr.y, cr.width,
cr.height);
cg.setColor(comp.getForeground());
cg.setFont(comp.getFont());
boolean shouldSetFlagBack = false;
try {
if(isJComponent) {
if(getFlag(ANCESTOR_USING_BUFFER)) {
((JComponent)comp).setFlag(
ANCESTOR_USING_BUFFER,true);
shouldSetFlagBack = true;
}
if(getFlag(IS_PAINTING_TILE)) {
((JComponent)comp).setFlag(
IS_PAINTING_TILE,true);
shouldSetFlagBack = true;
}
if(!printing) {
((JComponent)comp).paint(cg);
}
else {
if (!getFlag(IS_PRINTING_ALL)) {
comp.print(cg);
}
else {
comp.printAll(cg);
}
}
} else {
if (!printing) {
comp.paint(cg);
}
else {
if (!getFlag(IS_PRINTING_ALL)) {
comp.print(cg);
}
else {
comp.printAll(cg);
}
}
}
} finally {
cg.dispose();
if(shouldSetFlagBack) {
((JComponent)comp).setFlag(
ANCESTOR_USING_BUFFER,false);
((JComponent)comp).setFlag(
IS_PAINTING_TILE,false);
}
}
}
}
}
recycleRectangle(tmpRect);
}
|
protected void | paintComponent(java.awt.Graphics g)Calls the UI delegate's paint method, if the UI delegate
is non-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.
The passed in Graphics object might
have a transform other than the identify transform
installed on it. In this case, you might get
unexpected results if you cumulatively apply
another transform.
if (ui != null) {
Graphics scratchGraphics = (g == null) ? null : g.create();
try {
ui.update(scratchGraphics, this);
}
finally {
scratchGraphics.dispose();
}
}
|
void | paintForceDoubleBuffered(java.awt.Graphics g)
RepaintManager rm = RepaintManager.currentManager(this);
Rectangle clip = g.getClipBounds();
rm.beginPaint();
setFlag(IS_REPAINTING, true);
try {
rm.paint(this, this, g, clip.x, clip.y, clip.width, clip.height);
} finally {
rm.endPaint();
setFlag(IS_REPAINTING, false);
}
|
public 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.
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.
Component c = this;
Component parent;
if(!isShowing()) {
return;
}
while(!((JComponent)c).isOpaque()) {
parent = c.getParent();
if(parent != null) {
x += c.getX();
y += c.getY();
c = parent;
} else {
break;
}
if(!(c instanceof JComponent)) {
break;
}
}
if(c instanceof JComponent) {
((JComponent)c)._paintImmediately(x,y,w,h);
} else {
c.repaint(x,y,w,h);
}
|
public void | paintImmediately(java.awt.Rectangle r)Paints the specified region now.
paintImmediately(r.x,r.y,r.width,r.height);
|
void | paintToOffscreen(java.awt.Graphics g, int x, int y, int w, int h, int maxX, int maxY)Paints to the specified graphics. This does not set the clip and it
does not adjust the Graphics in anyway, callers must do that first.
This method is package-private for RepaintManager.PaintManager and
its subclasses to call, it is NOT intended for general use outside
of that.
try {
setFlag(ANCESTOR_USING_BUFFER, true);
if ((y + h) < maxY || (x + w) < maxX) {
setFlag(IS_PAINTING_TILE, true);
}
if (getFlag(IS_REPAINTING)) {
// Called from paintImmediately (RepaintManager) to fill
// repaint request
paint(g);
} else {
// Called from paint() (AWT) to repair damage
if(!rectangleIsObscured(x, y, w, h)) {
paintComponent(g);
paintBorder(g);
}
paintChildren(g);
}
} finally {
setFlag(ANCESTOR_USING_BUFFER, false);
setFlag(IS_PAINTING_TILE, false);
}
|
protected java.lang.String | paramString()Returns a string representation of this 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 .
String preferredSizeString = (isPreferredSizeSet() ?
getPreferredSize().toString() : "");
String minimumSizeString = (isMinimumSizeSet() ?
getMinimumSize().toString() : "");
String maximumSizeString = (isMaximumSizeSet() ?
getMaximumSize().toString() : "");
String borderString = (border != null ?
border.toString() : "");
return super.paramString() +
",alignmentX=" + alignmentX +
",alignmentY=" + alignmentY +
",border=" + borderString +
",flags=" + flags + // should beef this up a bit
",maximumSize=" + maximumSizeString +
",minimumSize=" + minimumSizeString +
",preferredSize=" + preferredSizeString;
|
public void | print(java.awt.Graphics g)Invoke this method to print the component to the specified
Graphics . This method will result in invocations
of printComponent , printBorder and
printChildren . It is recommended that you override
one of the previously mentioned methods rather than this one if
your intention is to customize the way printing looks. However,
it can be useful to override this method should you want to prepare
state before invoking the superclass behavior. As an example,
if you wanted to change the component's background color before
printing, you could do the following:
public void print(Graphics g) {
Color orig = getBackground();
setBackground(Color.WHITE);
// wrap in try/finally so that we always restore the state
try {
super.print(g);
} finally {
setBackground(orig);
}
}
Alternatively, or for components that delegate painting to other objects,
you can query during painting whether or not the component is in the
midst of a print operation. The isPaintingForPrint method provides
this ability and its return value will be changed by this method: to
true immediately before rendering and to false
immediately after. With each change a property change event is fired on
this component with the name "paintingForPrint" .
This method sets the component's state such that the double buffer
will not be used: painting will be done directly on the passed in
Graphics .
setFlag(IS_PRINTING, true);
firePropertyChange("paintingForPrint", false, true);
try {
paint(g);
}
finally {
setFlag(IS_PRINTING, false);
firePropertyChange("paintingForPrint", true, false);
}
|
public void | printAll(java.awt.Graphics g)Invoke this method to print the component. This method invokes
print on the component.
setFlag(IS_PRINTING_ALL, true);
try {
print(g);
}
finally {
setFlag(IS_PRINTING_ALL, false);
}
|
protected void | printBorder(java.awt.Graphics g)Prints the component's border. This is implemented to invoke
paintBorder on the component. Override this if you
wish to print the border differently that it is painted.
paintBorder(g);
|
protected void | printChildren(java.awt.Graphics g)Prints this component's children. This is implemented to invoke
paintChildren on the component. Override this if you
wish to print the children differently than painting.
paintChildren(g);
|
protected void | printComponent(java.awt.Graphics g)This is invoked during a printing operation. This is implemented to
invoke paintComponent on the component. Override this
if you wish to add special painting behavior when printing.
paintComponent(g);
|
protected void | processComponentKeyEvent(java.awt.event.KeyEvent e)Processes any key events that the component itself
recognizes. This is called after the focus
manager and any interested listeners have been
given a chance to steal away the event. This
method is called only if the event has not
yet been consumed. This method is called prior
to the keyboard UI logic.
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 boolean | processKeyBinding(javax.swing.KeyStroke ks, java.awt.event.KeyEvent e, int condition, boolean pressed)Invoked to process the key bindings for 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.
InputMap map = getInputMap(condition, false);
ActionMap am = getActionMap(false);
if(map != null && am != null && isEnabled()) {
Object binding = map.get(ks);
Action action = (binding == null) ? null : am.get(binding);
if (action != null) {
return SwingUtilities.notifyAction(action, ks, e, this,
e.getModifiers());
}
}
return false;
|
boolean | processKeyBindings(java.awt.event.KeyEvent e, boolean pressed)This is invoked as the result of a KeyEvent
that was not consumed by the FocusManager ,
KeyListeners , or the component. It will first try
WHEN_FOCUSED bindings,
then WHEN_ANCESTOR_OF_FOCUSED_COMPONENT bindings,
and finally WHEN_IN_FOCUSED_WINDOW bindings.
if (!SwingUtilities.isValidKeyEventForKeyBindings(e)) {
return false;
}
// Get the KeyStroke
KeyStroke ks;
if (e.getID() == KeyEvent.KEY_TYPED) {
ks = KeyStroke.getKeyStroke(e.getKeyChar());
}
else {
ks = KeyStroke.getKeyStroke(e.getKeyCode(),e.getModifiers(),
(pressed ? false:true));
}
/* Do we have a key binding for e? */
if(processKeyBinding(ks, e, WHEN_FOCUSED, pressed))
return true;
/* We have no key binding. Let's try the path from our parent to the
* window excluded. We store the path components so we can avoid
* asking the same component twice.
*/
Container parent = this;
while (parent != null && !(parent instanceof Window) &&
!(parent instanceof Applet)) {
if(parent instanceof JComponent) {
if(((JComponent)parent).processKeyBinding(ks, e,
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, pressed))
return true;
}
// This is done so that the children of a JInternalFrame are
// given precedence for WHEN_IN_FOCUSED_WINDOW bindings before
// other components WHEN_IN_FOCUSED_WINDOW bindings. This also gives
// more precedence to the WHEN_IN_FOCUSED_WINDOW bindings of the
// JInternalFrame's children vs the
// WHEN_ANCESTOR_OF_FOCUSED_COMPONENT bindings of the parents.
// maybe generalize from JInternalFrame (like isFocusCycleRoot).
if ((parent instanceof JInternalFrame) &&
JComponent.processKeyBindingsForAllComponents(e,parent,pressed)){
return true;
}
parent = parent.getParent();
}
/* No components between the focused component and the window is
* actually interested by the key event. Let's try the other
* JComponent in this window.
*/
if(parent != null) {
return JComponent.processKeyBindingsForAllComponents(e,parent,pressed);
}
return false;
|
static boolean | processKeyBindingsForAllComponents(java.awt.event.KeyEvent e, java.awt.Container container, boolean pressed)
while (true) {
if (KeyboardManager.getCurrentManager().fireKeyboardAction(
e, pressed, container)) {
return true;
}
if (container instanceof Popup.HeavyWeightWindow) {
container = ((Window)container).getOwner();
}
else {
return false;
}
}
|
protected void | processKeyEvent(java.awt.event.KeyEvent e)Overrides processKeyEvent to process events.
boolean result;
boolean shouldProcessKey;
// This gives the key event listeners a crack at the event
super.processKeyEvent(e);
// give the component itself a crack at the event
if (! e.isConsumed()) {
processComponentKeyEvent(e);
}
shouldProcessKey = KeyboardState.shouldProcess(e);
if(e.isConsumed()) {
return;
}
if (shouldProcessKey && processKeyBindings(e, e.getID() ==
KeyEvent.KEY_PRESSED)) {
e.consume();
}
|
protected void | processMouseEvent(java.awt.event.MouseEvent e)Processes mouse events occurring on this component by
dispatching them to any registered
MouseListener objects, refer to
{@link java.awt.Component#processMouseEvent(MouseEvent)}
for a complete description of this method.
if (autoscrolls && e.getID() == MouseEvent.MOUSE_RELEASED) {
Autoscroller.stop(this);
}
super.processMouseEvent(e);
|
protected void | processMouseMotionEvent(java.awt.event.MouseEvent e)Processes mouse motion events, such as MouseEvent.MOUSE_DRAGGED.
boolean dispatch = true;
if (autoscrolls && e.getID() == MouseEvent.MOUSE_DRAGGED) {
// We don't want to do the drags when the mouse moves if we're
// autoscrolling. It makes it feel spastic.
dispatch = !Autoscroller.isRunning(this);
Autoscroller.processMouseDragged(e);
}
if (dispatch) {
super.processMouseMotionEvent(e);
}
|
public final void | putClientProperty(java.lang.Object key, java.lang.Object value)Adds an arbitrary key/value "client property" to this component.
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.
if (key == SwingUtilities2.AA_TEXT_PROPERTY_KEY) {
aaTextInfo = value;
return;
}
if (value == null && clientProperties == null) {
// Both the value and ArrayTable are null, implying we don't
// have to do anything.
return;
}
ArrayTable clientProperties = getClientProperties();
Object oldValue;
synchronized(clientProperties) {
oldValue = clientProperties.get(key);
if (value != null) {
clientProperties.put(key, value);
} else if (oldValue != null) {
clientProperties.remove(key);
} else {
// old == new == null
return;
}
}
clientPropertyChanged(key, oldValue, value);
firePropertyChange(key.toString(), oldValue, value);
|
private void | readObject(java.io.ObjectInputStream s)We use the ObjectInputStream "registerValidation"
callback to update the UI for the entire tree of components
after they've all been read in.
s.defaultReadObject();
/* If there's no ReadObjectCallback for this stream yet, that is, if
* this is the first call to JComponent.readObject() for this
* graph of objects, then create a callback and stash it
* in the readObjectCallbacks table. Note that the ReadObjectCallback
* constructor takes care of calling s.registerValidation().
*/
ReadObjectCallback cb = (ReadObjectCallback)(readObjectCallbacks.get(s));
if (cb == null) {
try {
readObjectCallbacks.put(s, cb = new ReadObjectCallback(s));
}
catch (Exception e) {
throw new IOException(e.toString());
}
}
cb.registerComponent(this);
// Read back the client properties.
int cpCount = s.readInt();
if (cpCount > 0) {
clientProperties = new ArrayTable();
for (int counter = 0; counter < cpCount; counter++) {
clientProperties.put(s.readObject(),
s.readObject());
}
}
if (getToolTipText() != null) {
ToolTipManager.sharedInstance().registerComponent(this);
}
setWriteObjCounter(this, (byte)0);
|
boolean | rectangleIsObscured(int x, int y, int width, int height)If the specified rectangle is completely obscured by any of this
component's opaque children then returns true. Only direct children
are considered, more distant descendants are ignored. A
JComponent is opaque if
JComponent.isOpaque() returns true, other lightweight
components are always considered transparent, and heavyweight components
are always considered opaque.
int numChildren = getComponentCount();
for(int i = 0; i < numChildren; i++) {
Component child = getComponent(i);
int cx, cy, cw, ch;
cx = child.getX();
cy = child.getY();
cw = child.getWidth();
ch = child.getHeight();
if (x >= cx && (x + width) <= (cx + cw) &&
y >= cy && (y + height) <= (cy + ch) && child.isVisible()) {
if(child instanceof JComponent) {
// System.out.println("A) checking opaque: " + ((JComponent)child).isOpaque() + " " + child);
// System.out.print("B) ");
// Thread.dumpStack();
return ((JComponent)child).isOpaque();
} else {
/** Sometimes a heavy weight can have a bound larger than its peer size
* so we should always draw under heavy weights
*/
return false;
}
}
}
return false;
|
private static void | recycleRectangle(java.awt.Rectangle rect)
synchronized(tempRectangles) {
tempRectangles.add(rect);
}
|
public void | registerKeyboardAction(java.awt.event.ActionListener anAction, java.lang.String aCommand, javax.swing.KeyStroke aKeyStroke, int aCondition)This method is now obsolete, please use a combination of
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.
InputMap inputMap = getInputMap(aCondition, true);
if (inputMap != null) {
ActionMap actionMap = getActionMap(true);
ActionStandin action = new ActionStandin(anAction, aCommand);
inputMap.put(aKeyStroke, action);
if (actionMap != null) {
actionMap.put(action, action);
}
}
|
public void | registerKeyboardAction(java.awt.event.ActionListener anAction, javax.swing.KeyStroke aKeyStroke, int aCondition)This method is now obsolete, please use a combination of
getActionMap() and getInputMap() for
similiar behavior.
registerKeyboardAction(anAction,null,aKeyStroke,aCondition);
|
private void | registerNextFocusableComponent()
registerNextFocusableComponent(getNextFocusableComponent());
|
private void | registerNextFocusableComponent(java.awt.Component nextFocusableComponent)
if (nextFocusableComponent == null) {
return;
}
Container nearestRoot =
(isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
if (!(policy instanceof LegacyGlueFocusTraversalPolicy)) {
policy = new LegacyGlueFocusTraversalPolicy(policy);
nearestRoot.setFocusTraversalPolicy(policy);
}
((LegacyGlueFocusTraversalPolicy)policy).
setNextFocusableComponent(this, nextFocusableComponent);
|
private void | registerWithKeyboardManager(boolean onlyIfNew)Registers any bound WHEN_IN_FOCUSED_WINDOW actions with
the KeyboardManager . If onlyIfNew
is true only actions that haven't been registered are pushed
to the KeyboardManager ;
otherwise all actions are pushed to the KeyboardManager .
InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
KeyStroke[] strokes;
Hashtable registered = (Hashtable)getClientProperty
(WHEN_IN_FOCUSED_WINDOW_BINDINGS);
if (inputMap != null) {
// Push any new KeyStrokes to the KeyboardManager.
strokes = inputMap.allKeys();
if (strokes != null) {
for (int counter = strokes.length - 1; counter >= 0;
counter--) {
if (!onlyIfNew || registered == null ||
registered.get(strokes[counter]) == null) {
registerWithKeyboardManager(strokes[counter]);
}
if (registered != null) {
registered.remove(strokes[counter]);
}
}
}
}
else {
strokes = null;
}
// Remove any old ones.
if (registered != null && registered.size() > 0) {
Enumeration keys = registered.keys();
while (keys.hasMoreElements()) {
KeyStroke ks = (KeyStroke)keys.nextElement();
unregisterWithKeyboardManager(ks);
}
registered.clear();
}
// Updated the registered Hashtable.
if (strokes != null && strokes.length > 0) {
if (registered == null) {
registered = new Hashtable(strokes.length);
putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, registered);
}
for (int counter = strokes.length - 1; counter >= 0; counter--) {
registered.put(strokes[counter], strokes[counter]);
}
}
else {
putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, null);
}
|
private void | registerWithKeyboardManager(javax.swing.KeyStroke aKeyStroke)
KeyboardManager.getCurrentManager().registerKeyStroke(aKeyStroke,this);
|
public void | removeAncestorListener(javax.swing.event.AncestorListener listener)Unregisters listener so that it will no longer receive
AncestorEvents .
AncestorNotifier ancestorNotifier = getAncestorNotifier();
if (ancestorNotifier == null) {
return;
}
ancestorNotifier.removeAncestorListener(listener);
if (ancestorNotifier.listenerList.getListenerList().length == 0) {
ancestorNotifier.removeAllListeners();
putClientProperty(ANCESTOR_NOTIFIER_KEY, null);
}
|
public void | removeNotify()Notifies this component that it no longer has a parent component.
When this method is invoked, any KeyboardAction s
set up in the the chain of parent components are removed.
super.removeNotify();
// This isn't strictly correct. The event shouldn't be
// fired until *after* the parent is set to null. But
// we only get notified before that happens
firePropertyChange("ancestor", getParent(), null);
unregisterWithKeyboardManager();
deregisterNextFocusableComponent();
if (getCreatedDoubleBuffer()) {
RepaintManager.currentManager(this).resetDoubleBuffer();
setCreatedDoubleBuffer(false);
}
if (autoscrolls) {
Autoscroller.stop(this);
}
|
public synchronized void | removeVetoableChangeListener(java.beans.VetoableChangeListener listener)Removes a VetoableChangeListener from the listener list.
This removes a VetoableChangeListener that was registered
for all properties.
if (vetoableChangeSupport == null) {
return;
}
vetoableChangeSupport.removeVetoableChangeListener(listener);
|
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.
RepaintManager.currentManager(this).addDirtyRegion(this, x, y, width, height);
|
public void | repaint(java.awt.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.
repaint(0,r.x,r.y,r.width,r.height);
|
public boolean | requestDefaultFocus()In release 1.4, the focus subsystem was rearchitected.
For more information, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
Requests focus on this 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.
Container nearestRoot =
(isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
if (nearestRoot == null) {
return false;
}
Component comp = nearestRoot.getFocusTraversalPolicy().
getDefaultComponent(nearestRoot);
if (comp != null) {
comp.requestFocus();
return true;
} else {
return false;
}
|
public void | requestFocus()Requests that this Component gets the input focus.
Refer to {@link java.awt.Component#requestFocus()
Component.requestFocus()} for a complete description of
this method.
Note that the use of this method is discouraged because
its behavior is platform dependent. Instead we recommend the
use of {@link #requestFocusInWindow() requestFocusInWindow()}.
If you would like more information on focus, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
super.requestFocus();
|
public boolean | requestFocus(boolean temporary)Requests that this Component gets the input focus.
Refer to {@link java.awt.Component#requestFocus(boolean)
Component.requestFocus(boolean)} for a complete description of
this method.
Note that the use of this method is discouraged because
its behavior is platform dependent. Instead we recommend the
use of {@link #requestFocusInWindow(boolean)
requestFocusInWindow(boolean)}.
If you would like more information on focus, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
return super.requestFocus(temporary);
|
public boolean | requestFocusInWindow()Requests that this Component gets the input focus.
Refer to {@link java.awt.Component#requestFocusInWindow()
Component.requestFocusInWindow()} for a complete description of
this method.
If you would like more information on focus, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
return super.requestFocusInWindow();
|
protected boolean | requestFocusInWindow(boolean temporary)Requests that this Component gets the input focus.
Refer to {@link java.awt.Component#requestFocusInWindow(boolean)
Component.requestFocusInWindow(boolean)} for a complete description of
this method.
If you would like more information on focus, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
return super.requestFocusInWindow(temporary);
|
public void | resetKeyboardActions()Unregisters all the bindings in the first tier 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.
// Keys
for (int counter = 0; counter < 3; counter++) {
InputMap inputMap = getInputMap(counter, false);
if (inputMap != null) {
inputMap.clear();
}
}
// Actions
ActionMap am = getActionMap(false);
if (am != null) {
am.clear();
}
|
public void | reshape(int x, int y, int w, int h)
super.reshape(x, y, w, h);
|
public void | revalidate()Supports deferred automatic layout.
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.
if (getParent() == null) {
// Note: We don't bother invalidating here as once added
// to a valid parent invalidate will be invoked (addImpl
// invokes addNotify which will invoke invalidate on the
// new Component). Also, if we do add a check to isValid
// here it can potentially be called before the constructor
// which was causing some people grief.
return;
}
if (SwingUtilities.isEventDispatchThread()) {
invalidate();
RepaintManager.currentManager(this).addInvalidComponent(this);
}
else {
Runnable callRevalidate = new Runnable() {
public void run() {
revalidate();
}
};
SwingUtilities.invokeLater(callRevalidate);
}
|
static java.awt.Graphics | safelyGetGraphics(java.awt.Component c)
return safelyGetGraphics(c, SwingUtilities.getRoot(c));
|
static java.awt.Graphics | safelyGetGraphics(java.awt.Component c, java.awt.Component root)
synchronized(componentObtainingGraphicsFromLock) {
componentObtainingGraphicsFrom = root;
Graphics g = c.getGraphics();
componentObtainingGraphicsFrom = null;
return g;
}
|
public void | scrollRectToVisible(java.awt.Rectangle aRect)Forwards the scrollRectToVisible() message to the
JComponent 's parent. Components that can service
the request, such as JViewport ,
override this method and perform the scrolling.
Container parent;
int dx = getX(), dy = getY();
for (parent = getParent();
!(parent == null) &&
!(parent instanceof JComponent) &&
!(parent instanceof CellRendererPane);
parent = parent.getParent()) {
Rectangle bounds = parent.getBounds();
dx += bounds.x;
dy += bounds.y;
}
if (!(parent == null) && !(parent instanceof CellRendererPane)) {
aRect.x += dx;
aRect.y += dy;
((JComponent)parent).scrollRectToVisible(aRect);
aRect.x -= dx;
aRect.y -= dy;
}
|
public final void | setActionMap(javax.swing.ActionMap am)Sets the 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.
actionMap = am;
setFlag(ACTIONMAP_CREATED, true);
|
public void | setAlignmentX(float alignmentX)Sets the the vertical alignment.
this.alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f : alignmentX;
isAlignmentXSet = true;
|
public void | setAlignmentY(float alignmentY)Sets the the horizontal alignment.
this.alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f : alignmentY;
isAlignmentYSet = true;
|
public void | setAutoscrolls(boolean autoscrolls)Sets the 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 .
setFlag(AUTOSCROLLS_SET, true);
if (this.autoscrolls != autoscrolls) {
this.autoscrolls = autoscrolls;
if (autoscrolls) {
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
}
else {
Autoscroller.stop(this);
}
}
|
public void | setBackground(java.awt.Color bg)Sets the background color of this component. The background
color is used only if the component is opaque, and only
by subclasses of JComponent or
ComponentUI implementations. Direct subclasses of
JComponent must override
paintComponent to honor this property.
It is up to the look and feel to honor this property, some may
choose to ignore it.
Color oldBg = getBackground();
super.setBackground(bg);
if ((oldBg != null) ? !oldBg.equals(bg) : ((bg != null) && !bg.equals(oldBg))) {
// background already bound in AWT1.2
repaint();
}
|
public void | setBorder(javax.swing.border.Border border)Sets the border of this component. The 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.
Although technically you can set the border on any object
that inherits from JComponent , the look and
feel implementation of many standard Swing components
doesn't work well with user-set borders. In general,
when you want to set a border on a standard Swing
component other than JPanel or JLabel ,
we recommend that you put the component in a JPanel
and set the border on the JPanel .
This is a bound property.
Border oldBorder = this.border;
this.border = border;
firePropertyChange("border", oldBorder, border);
if (border != oldBorder) {
if (border == null || oldBorder == null ||
!(border.getBorderInsets(this).equals(oldBorder.getBorderInsets(this)))) {
revalidate();
}
repaint();
}
|
public void | setComponentPopupMenu(javax.swing.JPopupMenu popup)Sets the JPopupMenu for this JComponent .
The UI is responsible for registering bindings and adding the necessary
listeners such that the JPopupMenu will be shown at
the appropriate time. When the JPopupMenu is shown
depends upon the look and feel: some may show it on a mouse event,
some may enable a key binding.
If popup is null, and getInheritsPopupMenu
returns true, then getComponentPopupMenu will be delegated
to the parent. This provides for a way to make all child components
inherit the popupmenu of the parent.
This is a bound property.
if(popup != null) {
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
JPopupMenu oldPopup = this.popupMenu;
this.popupMenu = popup;
firePropertyChange("componentPopupMenu", oldPopup, popup);
|
void | setCreatedDoubleBuffer(boolean newValue)This is invoked by the RepaintManager if
createImage is called on the component.
setFlag(CREATED_DOUBLE_BUFFER, newValue);
|
public void | setDebugGraphicsOptions(int debugOptions)Enables or disables diagnostic information about every graphics
operation performed within the component or one of its children.
DebugGraphics.setDebugOptions(this, debugOptions);
|
public static void | setDefaultLocale(java.util.Locale l)Sets the default locale used to initialize each JComponent's locale
property upon creation. The initial value is the VM's default locale.
The default locale has "AppContext" scope so that applets (and
potentially multiple lightweight applications running in a single VM)
can have their own setting. An applet can safely alter its default
locale because it will have no affect on other applets (or the browser).
SwingUtilities.appContextPut(defaultLocale, l);
|
public void | setDoubleBuffered(boolean aFlag)Sets whether this 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.
If a Component is buffered and one of its ancestor
is also buffered, the ancestor buffer will be used.
setFlag(IS_DOUBLE_BUFFERED,aFlag);
|
java.lang.Object | setDropLocation(javax.swing.TransferHandler$DropLocation location, java.lang.Object state, boolean forDrop)Called to set or clear the drop location during a DnD operation.
In some cases, the component may need to use its internal selection
temporarily to indicate the drop location. To help facilitate this,
this method returns and accepts as a parameter a state object.
This state object can be used to store, and later restore, the selection
state. Whatever this method returns will be passed back to it in
future calls, as the state parameter. If it wants the DnD system to
continue storing the same state, it must pass it back every time.
Here's how this is used:
Let's say that on the first call to this method the component decides
to save some state (because it is about to use the selection to show
a drop index). It can return a state object to the caller encapsulating
any saved selection state. On a second call, let's say the drop location
is being changed to something else. The component doesn't need to
restore anything yet, so it simply passes back the same state object
to have the DnD system continue storing it. Finally, let's say this
method is messaged with null . This means DnD
is finished with this component for now, meaning it should restore
state. At this point, it can use the state parameter to restore
said state, and of course return null since there's
no longer anything to store.
return null;
|
public void | setEnabled(boolean enabled)Sets whether or not this component is enabled.
A component that is enabled may respond to user input,
while a component that is not enabled cannot respond to
user input. Some components may alter their visual
representation when they are disabled in order to
provide feedback to the user that they cannot take input.
Note: Disabling a component does not disable its children.
Note: Disabling a lightweight component does not prevent it from
receiving MouseEvents.
boolean oldEnabled = isEnabled();
super.setEnabled(enabled);
firePropertyChange("enabled", oldEnabled, enabled);
if (enabled != oldEnabled) {
repaint();
}
|
private void | setFlag(int aFlag, boolean aValue)
if(aValue) {
flags |= (1 << aFlag);
} else {
flags &= ~(1 << aFlag);
}
|
public void | setFocusTraversalKeys(int id, java.util.Set keystrokes)Sets the focus traversal keys for a given traversal operation for this
Component.
Refer to
{@link java.awt.Component#setFocusTraversalKeys}
for a complete description of this method.
if (id == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
setFlag(FOCUS_TRAVERSAL_KEYS_FORWARD_SET,true);
} else if (id == KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS) {
setFlag(FOCUS_TRAVERSAL_KEYS_BACKWARD_SET,true);
}
super.setFocusTraversalKeys(id,keystrokes);
|
public void | setFont(java.awt.Font font)Sets the font for this component.
Font oldFont = getFont();
super.setFont(font);
// font already bound in AWT1.2
if (font != oldFont) {
revalidate();
repaint();
}
|
public void | setForeground(java.awt.Color fg)Sets the foreground color of this component. It is up to the
look and feel to honor this property, some may choose to ignore
it.
Color oldFg = getForeground();
super.setForeground(fg);
if ((oldFg != null) ? !oldFg.equals(fg) : ((fg != null) && !fg.equals(oldFg))) {
// foreground already bound in AWT1.2
repaint();
}
|
public void | setInheritsPopupMenu(boolean value)Sets whether or not getComponentPopupMenu should delegate
to the parent if this component does not have a JPopupMenu
assigned to it.
The default value for this is false, but some JComponent
subclasses that are implemented as a number of JComponent s
may set this to true.
This is a bound property.
boolean oldValue = getFlag(INHERITS_POPUP_MENU);
setFlag(INHERITS_POPUP_MENU, value);
firePropertyChange("inheritsPopupMenu", oldValue, value);
|
public final void | setInputMap(int condition, javax.swing.InputMap map)Sets the 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
If 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.
switch (condition) {
case WHEN_IN_FOCUSED_WINDOW:
if (map != null && !(map instanceof ComponentInputMap)) {
throw new IllegalArgumentException("WHEN_IN_FOCUSED_WINDOW InputMaps must be of type ComponentInputMap");
}
windowInputMap = (ComponentInputMap)map;
setFlag(WIF_INPUTMAP_CREATED, true);
registerWithKeyboardManager(false);
break;
case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
ancestorInputMap = map;
setFlag(ANCESTOR_INPUTMAP_CREATED, true);
break;
case WHEN_FOCUSED:
focusInputMap = map;
setFlag(FOCUS_INPUTMAP_CREATED, true);
break;
default:
throw new IllegalArgumentException("condition must be one of JComponent.WHEN_IN_FOCUSED_WINDOW, JComponent.WHEN_FOCUSED or JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT");
}
|
public void | setInputVerifier(javax.swing.InputVerifier inputVerifier)Sets the input verifier for this component.
InputVerifier oldInputVerifier = (InputVerifier)getClientProperty(
INPUT_VERIFIER_KEY);
putClientProperty(INPUT_VERIFIER_KEY, inputVerifier);
firePropertyChange("inputVerifier", oldInputVerifier, inputVerifier);
|
public void | setMaximumSize(java.awt.Dimension maximumSize)Sets the maximum size of this component to a constant
value. Subsequent calls to 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.
super.setMaximumSize(maximumSize);
|
public void | setMinimumSize(java.awt.Dimension minimumSize)Sets the minimum size of this component to a constant
value. Subsequent calls to 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.
super.setMinimumSize(minimumSize);
|
public void | setNextFocusableComponent(java.awt.Component aComponent)In release 1.4, the focus subsystem was rearchitected.
For more information, see
How to Use the Focus Subsystem,
a section in The Java Tutorial.
Overrides the default 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.
boolean displayable = isDisplayable();
if (displayable) {
deregisterNextFocusableComponent();
}
putClientProperty(NEXT_FOCUS, aComponent);
if (displayable) {
registerNextFocusableComponent(aComponent);
}
|
public void | setOpaque(boolean isOpaque)If true the component paints every pixel within its bounds.
Otherwise, the component may not paint some or all of its
pixels, allowing the underlying pixels to show through.
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.
boolean oldValue = getFlag(IS_OPAQUE);
setFlag(IS_OPAQUE, isOpaque);
setFlag(OPAQUE_SET, true);
firePropertyChange("opaque", oldValue, isOpaque);
|
void | setPaintingChild(java.awt.Component paintingChild)
this.paintingChild = paintingChild;
|
public void | setPreferredSize(java.awt.Dimension preferredSize)Sets the preferred size of this component.
If preferredSize is null , the UI will
be asked for the preferred size.
super.setPreferredSize(preferredSize);
|
public void | setRequestFocusEnabled(boolean requestFocusEnabled)Provides a hint as to whether or not this 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.
Please see
How to Use the Focus Subsystem,
a section in The Java Tutorial,
for more information.
setFlag(REQUEST_FOCUS_DISABLED, !requestFocusEnabled);
|
public void | setToolTipText(java.lang.String text)Registers the text to display in a tool tip.
The text displays when the cursor lingers over the component.
See How to Use Tool Tips
in The Java Tutorial
for further documentation.
String oldText = getToolTipText();
putClientProperty(TOOL_TIP_TEXT_KEY, text);
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
if (text != null) {
if (oldText == null) {
toolTipManager.registerComponent(this);
}
} else {
toolTipManager.unregisterComponent(this);
}
|
public void | setTransferHandler(javax.swing.TransferHandler newHandler)Sets the 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.
Please see
How to Use Drag and Drop and Data Transfer,
a section in The Java Tutorial, for more information.
TransferHandler oldHandler = (TransferHandler)getClientProperty(
TRANSFER_HANDLER_KEY);
putClientProperty(TRANSFER_HANDLER_KEY, newHandler);
SwingUtilities.installSwingDropTargetAsNecessary(this, newHandler);
firePropertyChange("transferHandler", oldHandler, newHandler);
|
protected void | setUI(javax.swing.plaf.ComponentUI newUI)Sets the look and feel delegate for this component.
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;
}
/* We do not check that the UI instance is different
* before allowing the switch in order to enable the
* same UI instance *with different default settings*
* to be installed.
*/
if (ui != null) {
ui.uninstallUI(this);
//clean UIClientPropertyKeys from client properties
if (clientProperties != null) {
synchronized(clientProperties) {
Object[] clientPropertyKeys =
clientProperties.getKeys(null);
if (clientPropertyKeys != null) {
for (Object key : clientPropertyKeys) {
if (key instanceof UIClientPropertyKey) {
putClientProperty(key, null);
}
}
}
}
}
}
// aaText shouldn't persist between look and feels, reset it.
aaTextInfo =
UIManager.getDefaults().get(SwingUtilities2.AA_TEXT_PROPERTY_KEY);
ComponentUI oldUI = ui;
ui = newUI;
if (ui != null) {
ui.installUI(this);
}
firePropertyChange("UI", oldUI, newUI);
revalidate();
repaint();
|
void | setUIProperty(java.lang.String propertyName, java.lang.Object value)
if (propertyName == "opaque") {
if (!getFlag(OPAQUE_SET)) {
setOpaque(((Boolean)value).booleanValue());
setFlag(OPAQUE_SET, false);
}
} else if (propertyName == "autoscrolls") {
if (!getFlag(AUTOSCROLLS_SET)) {
setAutoscrolls(((Boolean)value).booleanValue());
setFlag(AUTOSCROLLS_SET, false);
}
} else if (propertyName == "focusTraversalKeysForward") {
if (!getFlag(FOCUS_TRAVERSAL_KEYS_FORWARD_SET)) {
super.setFocusTraversalKeys(KeyboardFocusManager.
FORWARD_TRAVERSAL_KEYS,
(Set)value);
}
} else if (propertyName == "focusTraversalKeysBackward") {
if (!getFlag(FOCUS_TRAVERSAL_KEYS_BACKWARD_SET)) {
super.setFocusTraversalKeys(KeyboardFocusManager.
BACKWARD_TRAVERSAL_KEYS,
(Set)value);
}
} else {
throw new IllegalArgumentException("property \""+
propertyName+ "\" cannot be set using this method");
}
|
public 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. The default is true. Set to false on components such as a
Cancel button or a scrollbar, which should activate even if the
input in the current focus owner is not "passed" by the input
verifier for that component.
boolean oldVerifyInputWhenFocusTarget =
this.verifyInputWhenFocusTarget;
this.verifyInputWhenFocusTarget = verifyInputWhenFocusTarget;
firePropertyChange("verifyInputWhenFocusTarget",
oldVerifyInputWhenFocusTarget,
verifyInputWhenFocusTarget);
|
public void | setVisible(boolean aFlag)Makes the component visible or invisible.
Overrides Component.setVisible .
if(aFlag != isVisible()) {
super.setVisible(aFlag);
Container parent = getParent();
if(parent != null) {
Rectangle r = getBounds();
parent.repaint(r.x,r.y,r.width,r.height);
}
// Some (all should) LayoutManagers do not consider components
// that are not visible. As such we need to revalidate when the
// visible bit changes.
revalidate();
}
|
static void | setWriteObjCounter(javax.swing.JComponent comp, byte count)
comp.flags = (comp.flags & ~(0xFF << WRITE_OBJ_COUNTER_FIRST)) |
(count << WRITE_OBJ_COUNTER_FIRST);
|
int | shouldDebugGraphics()Returns true if debug information is enabled for this
JComponent or one of its parents.
return DebugGraphics.shouldComponentDebug(this);
|
void | superProcessMouseMotionEvent(java.awt.event.MouseEvent e)
super.processMouseMotionEvent(e);
|
public void | unregisterKeyboardAction(javax.swing.KeyStroke aKeyStroke)This method is now obsolete. To unregister an existing binding
you can either remove the binding from the
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.
ActionMap am = getActionMap(false);
for (int counter = 0; counter < 3; counter++) {
InputMap km = getInputMap(counter, false);
if (km != null) {
Object actionID = km.get(aKeyStroke);
if (am != null && actionID != null) {
am.remove(actionID);
}
km.remove(aKeyStroke);
}
}
|
private void | unregisterWithKeyboardManager()Unregisters all the previously registered
WHEN_IN_FOCUSED_WINDOW KeyStroke bindings.
Hashtable registered = (Hashtable)getClientProperty
(WHEN_IN_FOCUSED_WINDOW_BINDINGS);
if (registered != null && registered.size() > 0) {
Enumeration keys = registered.keys();
while (keys.hasMoreElements()) {
KeyStroke ks = (KeyStroke)keys.nextElement();
unregisterWithKeyboardManager(ks);
}
}
putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, null);
|
private void | unregisterWithKeyboardManager(javax.swing.KeyStroke aKeyStroke)
KeyboardManager.getCurrentManager().unregisterKeyStroke(aKeyStroke,
this);
|
public void | update(java.awt.Graphics g)Calls paint . Doesn't clear the background but see
ComponentUI.update , which is called by
paintComponent .
paint(g);
|
public void | updateUI()Resets the UI property to a value from the current look and feel.
JComponent subclasses must override this method
like this:
public void updateUI() {
setUI((SliderUI)UIManager.getUI(this);
}
|
private void | writeObject(java.io.ObjectOutputStream s)Before writing a JComponent to an
ObjectOutputStream we temporarily uninstall its UI.
This is tricky to do because we want to uninstall
the UI before any of the JComponent 's children
(or its LayoutManager etc.) are written,
and we don't want to restore the UI until the most derived
JComponent subclass has been been stored.
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
ArrayTable.writeArrayTable(s, clientProperties);
|