src/java.desktop/share/classes/javax/swing/JComponent.java
Print this page
@@ -23,10 +23,11 @@
* questions.
*/
package javax.swing;
+import java.beans.*;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Vector;
@@ -34,14 +35,10 @@
import java.util.Set;
import java.awt.*;
import java.awt.event.*;
import java.awt.peer.LightweightPeer;
-import java.beans.PropertyChangeListener;
-import java.beans.VetoableChangeListener;
-import java.beans.VetoableChangeSupport;
-import java.beans.Transient;
import java.applet.Applet;
import java.io.Serializable;
import java.io.ObjectOutputStream;
@@ -174,10 +171,11 @@
*
* @author Hans Muller
* @author Arnaud Weber
* @since 1.2
*/
+@JavaBean(defaultProperty = "UIClassID")
@SuppressWarnings("serial") // Same-version serialization only
public abstract class JComponent extends Container implements Serializable,
TransferHandler.HasGetTransferHandler
{
/**
@@ -477,15 +475,14 @@
* <p>
* This is a bound property.
*
* @param value whether or not the JPopupMenu is inherited
* @see #setComponentPopupMenu
- * @beaninfo
- * bound: true
- * description: Whether or not the JPopupMenu is inherited
* @since 1.5
*/
+ @BeanProperty(description
+ = "Whether or not the JPopupMenu is inherited")
public void setInheritsPopupMenu(boolean value) {
boolean oldValue = getFlag(INHERITS_POPUP_MENU);
setFlag(INHERITS_POPUP_MENU, value);
firePropertyChange("inheritsPopupMenu", oldValue, value);
}
@@ -517,16 +514,14 @@
* This is a bound property.
*
* @param popup - the popup that will be assigned to this component
* may be null
* @see #getComponentPopupMenu
- * @beaninfo
- * bound: true
- * preferred: true
- * description: Popup to show
* @since 1.5
*/
+ @BeanProperty(preferred = true, description
+ = "Popup to show")
public void setComponentPopupMenu(JPopupMenu popup) {
if(popup != null) {
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
JPopupMenu oldPopup = this.popupMenu;
@@ -647,16 +642,13 @@
*
* @param newUI the new UI delegate
* @see #updateUI
* @see UIManager#getLookAndFeel
* @see UIManager#getUI
- * @beaninfo
- * bound: true
- * hidden: true
- * attribute: visualUpdate true
- * description: The component's look and feel delegate.
*/
+ @BeanProperty(hidden = true, visualUpdate = true, description
+ = "The component's look and feel delegate.")
protected void setUI(ComponentUI newUI) {
/* 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.
@@ -716,14 +708,13 @@
* <code>ComponentUI</code> subclass that defines their look and feel.
*
* @return the <code>UIDefaults</code> key for a
* <code>ComponentUI</code> subclass
* @see UIDefaults#getUI
- * @beaninfo
- * expert: true
- * description: UIClassID
*/
+ @BeanProperty(bound = false, expert = true, description
+ = "UIClassID")
public String getUIClassID() {
return uiClassID;
}
@@ -1263,10 +1254,11 @@
* Use this method to keep some state you might need between tiles.
*
* @return true if the component is currently painting a tile,
* false otherwise
*/
+ @BeanProperty(bound = false)
public boolean isPaintingTile() {
return getFlag(IS_PAINTING_TILE);
}
/**
@@ -1293,10 +1285,11 @@
* @return true if the current painting operation on this component
* is part of a print operation
* @see #print
* @since 1.6
*/
+ @BeanProperty(bound = false)
public final boolean isPaintingForPrint() {
return getFlag(IS_PRINTING);
}
/**
@@ -1317,10 +1310,11 @@
* @deprecated As of 1.4, replaced by
* <code>Component.setFocusTraversalKeys(int, Set)</code> and
* <code>Container.setFocusCycleRoot(boolean)</code>.
*/
@Deprecated
+ @BeanProperty(bound = false)
public boolean isManagingFocus() {
return false;
}
private void registerNextFocusableComponent() {
@@ -1587,15 +1581,13 @@
* @see #setInputVerifier
* @see #getInputVerifier
* @see #getVerifyInputWhenFocusTarget
*
* @since 1.3
- * @beaninfo
- * bound: true
- * description: Whether the Component verifies input before accepting
- * focus.
*/
+ @BeanProperty(description
+ = "Whether the Component verifies input before accepting focus.")
public void setVerifyInputWhenFocusTarget(boolean
verifyInputWhenFocusTarget) {
boolean oldVerifyInputWhenFocusTarget =
this.verifyInputWhenFocusTarget;
this.verifyInputWhenFocusTarget = verifyInputWhenFocusTarget;
@@ -1639,15 +1631,13 @@
/**
* Sets the preferred size of this component.
* If <code>preferredSize</code> is <code>null</code>, the UI will
* be asked for the preferred size.
- * @beaninfo
- * preferred: true
- * bound: true
- * description: The preferred size of the component.
*/
+ @BeanProperty(preferred = true, description
+ = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) {
super.setPreferredSize(preferredSize);
}
@@ -1683,14 +1673,13 @@
* restores the default behavior.
*
* @param maximumSize a <code>Dimension</code> containing the
* desired maximum allowable size
* @see #getMaximumSize
- * @beaninfo
- * bound: true
- * description: The maximum size of the component.
*/
+ @BeanProperty(description
+ = "The maximum size of the component.")
public void setMaximumSize(Dimension maximumSize) {
super.setMaximumSize(maximumSize);
}
@@ -1724,14 +1713,13 @@
* to compute it. Setting the minimum size to <code>null</code>
* restores the default behavior.
*
* @param minimumSize the new minimum size of this component
* @see #getMinimumSize
- * @beaninfo
- * bound: true
- * description: The minimum size of the component.
*/
+ @BeanProperty(description
+ = "The minimum size of the component.")
public void setMinimumSize(Dimension minimumSize) {
super.setMinimumSize(minimumSize);
}
/**
@@ -1791,16 +1779,13 @@
* This is a bound property.
*
* @param border the border to be rendered for this component
* @see Border
* @see CompoundBorder
- * @beaninfo
- * bound: true
- * preferred: true
- * attribute: visualUpdate true
- * description: The component's border.
*/
+ @BeanProperty(preferred = true, visualUpdate = true, description
+ = "The component's border.")
public void setBorder(Border border) {
Border oldBorder = this.border;
this.border = border;
firePropertyChange("border", oldBorder, border);
@@ -1829,10 +1814,11 @@
* border's insets; otherwise calls <code>super.getInsets</code>.
*
* @return the value of the insets property
* @see #setBorder
*/
+ @BeanProperty(expert = true)
public Insets getInsets() {
if (border != null) {
return border.getBorderInsets(this);
}
return super.getInsets();
@@ -1847,12 +1833,10 @@
* If <code>insets</code> is null, this will allocate a new one.
*
* @param insets the <code>Insets</code> object, which can be reused
* @return the <code>Insets</code> object
* @see #getInsets
- * @beaninfo
- * expert: true
*/
public Insets getInsets(Insets insets) {
if (insets == null) {
insets = new Insets(0, 0, 0, 0);
}
@@ -1890,13 +1874,13 @@
/**
* Sets the vertical alignment.
*
* @param alignmentY the new vertical alignment
* @see #getAlignmentY
- * @beaninfo
- * description: The preferred vertical alignment of the component.
*/
+ @BeanProperty(description
+ = "The preferred vertical alignment of the component.")
public void setAlignmentY(float alignmentY) {
this.alignmentY = validateAlignment(alignmentY);
isAlignmentYSet = true;
}
@@ -1919,13 +1903,13 @@
/**
* Sets the horizontal alignment.
*
* @param alignmentX the new horizontal alignment
* @see #getAlignmentX
- * @beaninfo
- * description: The preferred horizontal alignment of the component.
*/
+ @BeanProperty(description
+ = "The preferred horizontal alignment of the component.")
public void setAlignmentX(float alignmentX) {
this.alignmentX = validateAlignment(alignmentX);
isAlignmentXSet = true;
}
@@ -1937,14 +1921,13 @@
* Sets the input verifier for this component.
*
* @param inputVerifier the new input verifier
* @since 1.3
* @see InputVerifier
- * @beaninfo
- * bound: true
- * description: The component's input verifier.
*/
+ @BeanProperty(description
+ = "The component's input verifier.")
public void setInputVerifier(InputVerifier inputVerifier) {
InputVerifier oldInputVerifier = (InputVerifier)getClientProperty(
JComponent_INPUT_VERIFIER);
putClientProperty(JComponent_INPUT_VERIFIER, inputVerifier);
firePropertyChange("inputVerifier", oldInputVerifier, inputVerifier);
@@ -1965,10 +1948,11 @@
* Returns this component's graphics context, which lets you draw
* on a component. Use this method to get a <code>Graphics</code> object and
* then invoke operations on that object to draw on the component.
* @return this components graphics context
*/
+ @BeanProperty(bound = false)
public Graphics getGraphics() {
if (DEBUG_GRAPHICS_LOADED && shouldDebugGraphics() != 0) {
DebugGraphics graphics = new DebugGraphics(super.getGraphics(),
this);
return graphics;
@@ -1991,19 +1975,17 @@
* performed on the View's offscreen buffer.
* <li>DebugGraphics.NONE_OPTION disables debugging.
* <li>A value of 0 causes no changes to the debugging options.
* </ul>
* <code>debugOptions</code> is bitwise OR'd into the current value
- *
- * @beaninfo
- * preferred: true
- * enum: NONE_OPTION DebugGraphics.NONE_OPTION
- * LOG_OPTION DebugGraphics.LOG_OPTION
- * FLASH_OPTION DebugGraphics.FLASH_OPTION
- * BUFFERED_OPTION DebugGraphics.BUFFERED_OPTION
- * description: Diagnostic options for graphics operations.
*/
+ @BeanProperty(bound = false, preferred = true, enumerationValues = {
+ "DebugGraphics.NONE_OPTION",
+ "DebugGraphics.LOG_OPTION",
+ "DebugGraphics.FLASH_OPTION",
+ "DebugGraphics.BUFFERED_OPTION"}, description
+ = "Diagnostic options for graphics operations.")
public void setDebugGraphicsOptions(int debugOptions) {
DebugGraphics.setDebugOptions(this, debugOptions);
}
/** Returns the state of graphics debugging.
@@ -2276,10 +2258,11 @@
* registered actions.
*
* @return an array of <code>KeyStroke</code> objects
* @see #registerKeyboardAction
*/
+ @BeanProperty(bound = false)
public KeyStroke[] getRegisteredKeyStrokes() {
int[] counts = new int[3];
KeyStroke[][] strokes = new KeyStroke[3][];
for (int counter = 0; counter < 3; counter++) {
@@ -2614,10 +2597,11 @@
* <code>getBaseline</code> returns a value less than 0.
*
* @see #getBaseline(int, int)
* @since 1.6
*/
+ @BeanProperty(bound = false)
public BaselineResizeBehavior getBaselineResizeBehavior() {
if (ui != null) {
return ui.getBaselineResizeBehavior(this);
}
return BaselineResizeBehavior.OTHER;
@@ -2664,14 +2648,12 @@
* Makes the component visible or invisible.
* Overrides <code>Component.setVisible</code>.
*
* @param aFlag true to make the component visible; false to
* make it invisible
- *
- * @beaninfo
- * attribute: visualUpdate true
*/
+ @BeanProperty(hidden = true, visualUpdate = true)
public void setVisible(boolean aFlag) {
if (aFlag != isVisible()) {
super.setVisible(aFlag);
if (aFlag) {
Container parent = getParent();
@@ -2697,17 +2679,13 @@
* receiving MouseEvents.
*
* @param enabled true if this component should be enabled, false otherwise
* @see java.awt.Component#isEnabled
* @see java.awt.Component#isLightweight
- *
- * @beaninfo
- * preferred: true
- * bound: true
- * attribute: visualUpdate true
- * description: The enabled state of the component.
*/
+ @BeanProperty(expert = true, preferred = true, visualUpdate = true, description
+ = "The enabled state of the component.")
public void setEnabled(boolean enabled) {
boolean oldEnabled = isEnabled();
super.setEnabled(enabled);
firePropertyChange("enabled", oldEnabled, enabled);
if (enabled != oldEnabled) {
@@ -2720,17 +2698,13 @@
* look and feel to honor this property, some may choose to ignore
* it.
*
* @param fg the desired foreground <code>Color</code>
* @see java.awt.Component#getForeground
- *
- * @beaninfo
- * preferred: true
- * bound: true
- * attribute: visualUpdate true
- * description: The foreground color of the component.
*/
+ @BeanProperty(preferred = true, visualUpdate = true, description
+ = "The foreground color of the component.")
public void setForeground(Color fg) {
Color oldFg = getForeground();
super.setForeground(fg);
if ((oldFg != null) ? !oldFg.equals(fg) : ((fg != null) && !fg.equals(oldFg))) {
// foreground already bound in AWT1.2
@@ -2750,17 +2724,13 @@
* choose to ignore it.
*
* @param bg the desired background <code>Color</code>
* @see java.awt.Component#getBackground
* @see #setOpaque
- *
- * @beaninfo
- * preferred: true
- * bound: true
- * attribute: visualUpdate true
- * description: The background color of the component.
*/
+ @BeanProperty(preferred = true, visualUpdate = true, description
+ = "The background color of the component.")
public void setBackground(Color bg) {
Color oldBg = getBackground();
super.setBackground(bg);
if ((oldBg != null) ? !oldBg.equals(bg) : ((bg != null) && !bg.equals(oldBg))) {
// background already bound in AWT1.2
@@ -2771,17 +2741,13 @@
/**
* Sets the font for this component.
*
* @param font the desired <code>Font</code> for this component
* @see java.awt.Component#getFont
- *
- * @beaninfo
- * preferred: true
- * bound: true
- * attribute: visualUpdate true
- * description: The font for the component.
*/
+ @BeanProperty(preferred = true, visualUpdate = true, description
+ = "The font for the component.")
public void setFont(Font font) {
Font oldFont = getFont();
super.setFont(font);
// font already bound in AWT1.2
if (font != oldFont) {
@@ -3026,14 +2992,13 @@
* for further documentation.
*
* @param text the string to display; if the text is <code>null</code>,
* the tool tip is turned off for this component
* @see #TOOL_TIP_TEXT_KEY
- * @beaninfo
- * preferred: true
- * description: The text to display in a tool tip.
*/
+ @BeanProperty(bound = false, preferred = true, description
+ = "The text to display in a tool tip.")
public void setToolTipText(String text) {
String oldText = getToolTipText();
putClientProperty(TOOL_TIP_TEXT_KEY, text);
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
if (text != null) {
@@ -3188,15 +3153,13 @@
* bounds and the mouse button continues to be held down; otherwise
* false
* @see #getAutoscrolls
* @see JViewport
* @see JScrollPane
- *
- * @beaninfo
- * expert: true
- * description: Determines if this component automatically scrolls its contents when dragged.
*/
+ @BeanProperty(bound = false, expert = true, description
+ = "Determines if this component automatically scrolls its contents when dragged.")
public void setAutoscrolls(boolean autoscrolls) {
setFlag(AUTOSCROLLS_SET, true);
if (this.autoscrolls != autoscrolls) {
this.autoscrolls = autoscrolls;
if (autoscrolls) {
@@ -3252,15 +3215,13 @@
* @param newHandler the new {@code TransferHandler}
*
* @see TransferHandler
* @see #getTransferHandler
* @since 1.4
- * @beaninfo
- * bound: true
- * hidden: true
- * description: Mechanism for transfer of data to and from the component
*/
+ @BeanProperty(hidden = true, description
+ = "Mechanism for transfer of data to and from the component")
public void setTransferHandler(TransferHandler newHandler) {
TransferHandler oldHandler = (TransferHandler)getClientProperty(
JComponent_TRANSFER_HANDLER);
putClientProperty(JComponent_TRANSFER_HANDLER, newHandler);
@@ -4208,12 +4169,10 @@
* KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes
* contains null, or if any keystroke represents a KEY_TYPED event,
* or if any keystroke already maps to another focus traversal
* operation for this Component
* @since 1.5
- * @beaninfo
- * bound: true
*/
public void
setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
{
if (id == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
@@ -4336,10 +4295,11 @@
* <code>component.getLocation().x</code> because it doesn't cause any
* heap allocations.
*
* @return the current x coordinate of the component's origin
*/
+ @BeanProperty(bound = false)
public int getX() { return super.getX(); }
/**
* Returns the current y coordinate of the component's origin.
@@ -4348,10 +4308,11 @@
* <code>component.getLocation().y</code> because it doesn't cause any
* heap allocations.
*
* @return the current y coordinate of the component's origin
*/
+ @BeanProperty(bound = false)
public int getY() { return super.getY(); }
/**
* Returns the current width of this component.
@@ -4360,10 +4321,11 @@
* <code>component.getSize().width</code> because it doesn't cause any
* heap allocations.
*
* @return the current width of this component
*/
+ @BeanProperty(bound = false)
public int getWidth() { return super.getWidth(); }
/**
* Returns the current height of this component.
@@ -4372,10 +4334,11 @@
* <code>component.getSize().height</code> because it doesn't cause any
* heap allocations.
*
* @return the current height of this component
*/
+ @BeanProperty(bound = false)
public int getHeight() { return super.getHeight(); }
/**
* Returns true if this component is completely opaque.
* <p>
@@ -4405,15 +4368,13 @@
* <code>JComponent</code> subclasses (such as <code>JButton</code> and
* <code>JTree</code>) is look-and-feel dependent.
*
* @param isOpaque true if this component should be opaque
* @see #isOpaque
- * @beaninfo
- * bound: true
- * expert: true
- * description: The component's opacity
*/
+ @BeanProperty(expert = true, description
+ = "The component's opacity")
public void setOpaque(boolean isOpaque) {
boolean oldValue = getFlag(IS_OPAQUE);
setFlag(IS_OPAQUE, isOpaque);
setFlag(OPAQUE_SET, true);
firePropertyChange("opaque", oldValue, isOpaque);
@@ -4520,10 +4481,11 @@
* <code>new Rectangle(0, 0, getWidth(), getHeight())</code>,
* and all of its ancestors' visible rectangles.
*
* @return the visible rectangle
*/
+ @BeanProperty(bound = false)
public Rectangle getVisibleRect() {
Rectangle visibleRect = new Rectangle();
computeVisibleRect(visibleRect);
return visibleRect;
@@ -4628,10 +4590,11 @@
* @see #addVetoableChangeListener
* @see #removeVetoableChangeListener
*
* @since 1.4
*/
+ @BeanProperty(bound = false)
public synchronized VetoableChangeListener[] getVetoableChangeListeners() {
if (vetoableChangeSupport == null) {
return new VetoableChangeListener[0];
}
return vetoableChangeSupport.getVetoableChangeListeners();
@@ -4645,10 +4608,11 @@
* been added to any container.
*
* @return the top-level <code>Container</code> that this component is in,
* or <code>null</code> if not in any container
*/
+ @BeanProperty(bound = false)
public Container getTopLevelAncestor() {
for(Container p = this; p != null; p = p.getParent()) {
if(p instanceof Window || p instanceof Applet) {
return p;
}
@@ -4711,10 +4675,11 @@
* @see #addAncestorListener
* @see #removeAncestorListener
*
* @since 1.4
*/
+ @BeanProperty(bound = false)
public AncestorListener[] getAncestorListeners() {
AncestorNotifier ancestorNotifier = getAncestorNotifier();
if (ancestorNotifier == null) {
return new AncestorListener[0];
}
@@ -4943,10 +4908,11 @@
* guarantee, such as <code>JLayeredPane</code>,
* should override this method to return false.
*
* @return always returns true
*/
+ @BeanProperty(bound = false)
public boolean isOptimizedDrawingEnabled() {
return true;
}
/**
@@ -5392,10 +5358,11 @@
* Returns the <code>JRootPane</code> ancestor for this component.
*
* @return the <code>JRootPane</code> that contains this component,
* or <code>null</code> if no <code>JRootPane</code> is found
*/
+ @BeanProperty(bound = false)
public JRootPane getRootPane() {
return SwingUtilities.getRootPane(this);
}