src/share/classes/javax/swing/JComponent.java

Print this page




  61 import javax.swing.event.*;
  62 import javax.swing.plaf.*;
  63 import static javax.swing.ClientPropertyKey.*;
  64 import javax.accessibility.*;
  65 
  66 import sun.swing.SwingUtilities2;
  67 import sun.swing.UIClientPropertyKey;
  68 
  69 /**
  70  * The base class for all Swing components except top-level containers.
  71  * To use a component that inherits from <code>JComponent</code>,
  72  * you must place the component in a containment hierarchy
  73  * whose root is a top-level Swing container.
  74  * Top-level Swing containers --
  75  * such as <code>JFrame</code>, <code>JDialog</code>,
  76  * and <code>JApplet</code> --
  77  * are specialized components
  78  * that provide a place for other Swing components to paint themselves.
  79  * For an explanation of containment hierarchies, see
  80  * <a
  81  href="http://java.sun.com/docs/books/tutorial/uiswing/overview/hierarchy.html">Swing Components and the Containment Hierarchy</a>,
  82  * a section in <em>The Java Tutorial</em>.
  83  *
  84  * <p>
  85  * The <code>JComponent</code> class provides:
  86  * <ul>
  87  * <li>The base class for both standard and custom components
  88  *     that use the Swing architecture.
  89  * <li>A "pluggable look and feel" (L&amp;F) that can be specified by the
  90  *     programmer or (optionally) selected by the user at runtime.
  91  *     The look and feel for each component is provided by a
  92  *     <em>UI delegate</em> -- an object that descends from
  93  *     {@link javax.swing.plaf.ComponentUI}.
  94  *     See <a
  95  * href="http://java.sun.com/docs/books/tutorial/uiswing/misc/plaf.html">How
  96  *     to Set the Look and Feel</a>
  97  *     in <em>The Java Tutorial</em>
  98  *     for more information.
  99  * <li>Comprehensive keystroke handling.
 100  *     See the document <a
 101  * href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html">Keyboard
 102  *     Bindings in Swing</a>,
 103  *     an article in <em>The Swing Connection</em>,
 104  *     for more information.
 105  * <li>Support for tool tips --
 106  *     short descriptions that pop up when the cursor lingers
 107  *     over a component.
 108  *     See <a
 109  * href="http://java.sun.com/docs/books/tutorial/uiswing/components/tooltip.html">How
 110  *     to Use Tool Tips</a>
 111  *     in <em>The Java Tutorial</em>
 112  *     for more information.
 113  * <li>Support for accessibility.
 114  *     <code>JComponent</code> contains all of the methods in the
 115  *     <code>Accessible</code> interface,
 116  *     but it doesn't actually implement the interface.  That is the
 117  *     responsibility of the individual classes
 118  *     that extend <code>JComponent</code>.
 119  * <li>Support for component-specific properties.
 120  *     With the {@link #putClientProperty}
 121  *     and {@link #getClientProperty} methods,
 122  *     you can associate name-object pairs
 123  *     with any object that descends from <code>JComponent</code>.
 124  * <li>An infrastructure for painting
 125  *     that includes double buffering and support for borders.
 126  *     For more information see <a
 127  * href="http://java.sun.com/docs/books/tutorial/uiswing/overview/draw.html">Painting</a> and
 128  * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/border.html">How
 129  *     to Use Borders</a>,
 130  *     both of which are sections in <em>The Java Tutorial</em>.
 131  * </ul>
 132  * For more information on these subjects, see the
 133  * <a href="package-summary.html#package_description">Swing package description</a>
 134  * and <em>The Java Tutorial</em> section
 135  * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/jcomponent.html">The JComponent Class</a>.
 136  * <p>
 137  * <code>JComponent</code> and its subclasses document default values
 138  * for certain properties.  For example, <code>JTable</code> documents the
 139  * default row height as 16.  Each <code>JComponent</code> subclass
 140  * that has a <code>ComponentUI</code> will create the
 141  * <code>ComponentUI</code> as part of its constructor.  In order
 142  * to provide a particular look and feel each
 143  * <code>ComponentUI</code> may set properties back on the
 144  * <code>JComponent</code> that created it.  For example, a custom
 145  * look and feel may require <code>JTable</code>s to have a row
 146  * height of 24. The documented defaults are the value of a property
 147  * BEFORE the <code>ComponentUI</code> has been installed.  If you
 148  * need a specific value for a particular property you should
 149  * explicitly set it.
 150  * <p>
 151  * In release 1.4, the focus subsystem was rearchitected.
 152  * For more information, see
 153  * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
 154  * How to Use the Focus Subsystem</a>,
 155  * a section in <em>The Java Tutorial</em>.
 156  * <p>
 157  * <strong>Warning:</strong> Swing is not thread safe. For more
 158  * information see <a
 159  * href="package-summary.html#threading">Swing's Threading
 160  * Policy</a>.
 161  * <p>
 162  * <strong>Warning:</strong>
 163  * Serialized objects of this class will not be compatible with
 164  * future Swing releases. The current serialization support is
 165  * appropriate for short term storage or RMI between applications running
 166  * the same version of Swing.  As of 1.4, support for long term storage
 167  * of all JavaBeans<sup><font size="-2">TM</font></sup>
 168  * has been added to the <code>java.beans</code> package.
 169  * Please see {@link java.beans.XMLEncoder}.
 170  *
 171  * @see KeyStroke
 172  * @see Action
 173  * @see #setBorder


1274      * level print processes. For example, a {@link javax.swing.JTable#print()}
1275      * operation doesn't necessarily result in a continuous rendering of the
1276      * full component, and the return value of this method can change multiple
1277      * times during that operation. It is even possible for the component to be
1278      * painted to the screen while the printing process is ongoing. In such a
1279      * case, the return value of this method is <code>true</code> when, and only
1280      * when, the table is being painted as part of the printing process.
1281      *
1282      * @return true if the current painting operation on this component
1283      *         is part of a print operation
1284      * @see #print
1285      * @since 1.6
1286      */
1287     public final boolean isPaintingForPrint() {
1288         return getFlag(IS_PRINTING);
1289     }
1290 
1291     /**
1292      * In release 1.4, the focus subsystem was rearchitected.
1293      * For more information, see
1294      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1295      * How to Use the Focus Subsystem</a>,
1296      * a section in <em>The Java Tutorial</em>.
1297      * <p>
1298      * Changes this <code>JComponent</code>'s focus traversal keys to
1299      * CTRL+TAB and CTRL+SHIFT+TAB. Also prevents
1300      * <code>SortingFocusTraversalPolicy</code> from considering descendants
1301      * of this JComponent when computing a focus traversal cycle.
1302      *
1303      * @see java.awt.Component#setFocusTraversalKeys
1304      * @see SortingFocusTraversalPolicy
1305      * @deprecated As of 1.4, replaced by
1306      *   <code>Component.setFocusTraversalKeys(int, Set)</code> and
1307      *   <code>Container.setFocusCycleRoot(boolean)</code>.
1308      */
1309     @Deprecated
1310     public boolean isManagingFocus() {
1311         return false;
1312     }
1313 
1314     private void registerNextFocusableComponent() {


1336         Component nextFocusableComponent = getNextFocusableComponent();
1337         if (nextFocusableComponent == null) {
1338             return;
1339         }
1340 
1341         Container nearestRoot =
1342             (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
1343         if (nearestRoot == null) {
1344             return;
1345         }
1346         FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
1347         if (policy instanceof LegacyGlueFocusTraversalPolicy) {
1348             ((LegacyGlueFocusTraversalPolicy)policy).
1349                 unsetNextFocusableComponent(this, nextFocusableComponent);
1350         }
1351     }
1352 
1353     /**
1354      * In release 1.4, the focus subsystem was rearchitected.
1355      * For more information, see
1356      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1357      * How to Use the Focus Subsystem</a>,
1358      * a section in <em>The Java Tutorial</em>.
1359      * <p>
1360      * Overrides the default <code>FocusTraversalPolicy</code> for this
1361      * <code>JComponent</code>'s focus traversal cycle by unconditionally
1362      * setting the specified <code>Component</code> as the next
1363      * <code>Component</code> in the cycle, and this <code>JComponent</code>
1364      * as the specified <code>Component</code>'s previous
1365      * <code>Component</code> in the cycle.
1366      *
1367      * @param aComponent the <code>Component</code> that should follow this
1368      *        <code>JComponent</code> in the focus traversal cycle
1369      *
1370      * @see #getNextFocusableComponent
1371      * @see java.awt.FocusTraversalPolicy
1372      * @deprecated As of 1.4, replaced by <code>FocusTraversalPolicy</code>
1373      */
1374     @Deprecated
1375     public void setNextFocusableComponent(Component aComponent) {
1376         boolean displayable = isDisplayable();
1377         if (displayable) {
1378             deregisterNextFocusableComponent();
1379         }
1380         putClientProperty(NEXT_FOCUS, aComponent);
1381         if (displayable) {
1382             registerNextFocusableComponent(aComponent);
1383         }
1384     }
1385 
1386     /**
1387      * In release 1.4, the focus subsystem was rearchitected.
1388      * For more information, see
1389      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1390      * How to Use the Focus Subsystem</a>,
1391      * a section in <em>The Java Tutorial</em>.
1392      * <p>
1393      * Returns the <code>Component</code> set by a prior call to
1394      * <code>setNextFocusableComponent(Component)</code> on this
1395      * <code>JComponent</code>.
1396      *
1397      * @return the <code>Component</code> that will follow this
1398      *        <code>JComponent</code> in the focus traversal cycle, or
1399      *        <code>null</code> if none has been explicitly specified
1400      *
1401      * @see #setNextFocusableComponent
1402      * @deprecated As of 1.4, replaced by <code>FocusTraversalPolicy</code>.
1403      */
1404     @Deprecated
1405     public Component getNextFocusableComponent() {
1406         return (Component)getClientProperty(NEXT_FOCUS);
1407     }
1408 
1409     /**
1410      * Provides a hint as to whether or not this <code>JComponent</code>
1411      * should get focus. This is only a hint, and it is up to consumers that
1412      * are requesting focus to honor this property. This is typically honored
1413      * for mouse operations, but not keyboard operations. For example, look
1414      * and feels could verify this property is true before requesting focus
1415      * during a mouse operation. This would often times be used if you did
1416      * not want a mouse press on a <code>JComponent</code> to steal focus,
1417      * but did want the <code>JComponent</code> to be traversable via the
1418      * keyboard. If you do not want this <code>JComponent</code> focusable at
1419      * all, use the <code>setFocusable</code> method instead.
1420      * <p>
1421      * Please see
1422      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1423      * How to Use the Focus Subsystem</a>,
1424      * a section in <em>The Java Tutorial</em>,
1425      * for more information.
1426      *
1427      * @param requestFocusEnabled indicates whether you want this
1428      *        <code>JComponent</code> to be focusable or not
1429      * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
1430      * @see java.awt.Component#setFocusable
1431      */
1432     public void setRequestFocusEnabled(boolean requestFocusEnabled) {
1433         setFlag(REQUEST_FOCUS_DISABLED, !requestFocusEnabled);
1434     }
1435 
1436     /**
1437      * Returns <code>true</code> if this <code>JComponent</code> should
1438      * get focus; otherwise returns <code>false</code>.
1439      * <p>
1440      * Please see
1441      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1442      * How to Use the Focus Subsystem</a>,
1443      * a section in <em>The Java Tutorial</em>,
1444      * for more information.
1445      *
1446      * @return <code>true</code> if this component should get focus,
1447      *     otherwise returns <code>false</code>
1448      * @see #setRequestFocusEnabled
1449      * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus
1450      *      Specification</a>
1451      * @see java.awt.Component#isFocusable
1452      */
1453     public boolean isRequestFocusEnabled() {
1454         return !getFlag(REQUEST_FOCUS_DISABLED);
1455     }
1456 
1457     /**
1458      * Requests that this <code>Component</code> gets the input focus.
1459      * Refer to {@link java.awt.Component#requestFocus()
1460      * Component.requestFocus()} for a complete description of
1461      * this method.
1462      * <p>
1463      * Note that the use of this method is discouraged because
1464      * its behavior is platform dependent. Instead we recommend the
1465      * use of {@link #requestFocusInWindow() requestFocusInWindow()}.
1466      * If you would like more information on focus, see
1467      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1468      * How to Use the Focus Subsystem</a>,
1469      * a section in <em>The Java Tutorial</em>.
1470      *
1471      * @see java.awt.Component#requestFocusInWindow()
1472      * @see java.awt.Component#requestFocusInWindow(boolean)
1473      * @since 1.4
1474      */
1475     public void requestFocus() {
1476         super.requestFocus();
1477     }
1478 
1479     /**
1480      * Requests that this <code>Component</code> gets the input focus.
1481      * Refer to {@link java.awt.Component#requestFocus(boolean)
1482      * Component.requestFocus(boolean)} for a complete description of
1483      * this method.
1484      * <p>
1485      * Note that the use of this method is discouraged because
1486      * its behavior is platform dependent. Instead we recommend the
1487      * use of {@link #requestFocusInWindow(boolean)
1488      * requestFocusInWindow(boolean)}.
1489      * If you would like more information on focus, see
1490      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1491      * How to Use the Focus Subsystem</a>,
1492      * a section in <em>The Java Tutorial</em>.
1493      *
1494      * @param temporary boolean indicating if the focus change is temporary
1495      * @return <code>false</code> if the focus change request is guaranteed to
1496      *         fail; <code>true</code> if it is likely to succeed
1497      * @see java.awt.Component#requestFocusInWindow()
1498      * @see java.awt.Component#requestFocusInWindow(boolean)
1499      * @since 1.4
1500      */
1501     public boolean requestFocus(boolean temporary) {
1502         return super.requestFocus(temporary);
1503     }
1504 
1505     /**
1506      * Requests that this <code>Component</code> gets the input focus.
1507      * Refer to {@link java.awt.Component#requestFocusInWindow()
1508      * Component.requestFocusInWindow()} for a complete description of
1509      * this method.
1510      * <p>
1511      * If you would like more information on focus, see
1512      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1513      * How to Use the Focus Subsystem</a>,
1514      * a section in <em>The Java Tutorial</em>.
1515      *
1516      * @return <code>false</code> if the focus change request is guaranteed to
1517      *         fail; <code>true</code> if it is likely to succeed
1518      * @see java.awt.Component#requestFocusInWindow()
1519      * @see java.awt.Component#requestFocusInWindow(boolean)
1520      * @since 1.4
1521      */
1522     public boolean requestFocusInWindow() {
1523         return super.requestFocusInWindow();
1524     }
1525 
1526     /**
1527      * Requests that this <code>Component</code> gets the input focus.
1528      * Refer to {@link java.awt.Component#requestFocusInWindow(boolean)
1529      * Component.requestFocusInWindow(boolean)} for a complete description of
1530      * this method.
1531      * <p>
1532      * If you would like more information on focus, see
1533      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
1534      * How to Use the Focus Subsystem</a>,
1535      * a section in <em>The Java Tutorial</em>.
1536      *
1537      * @param temporary boolean indicating if the focus change is temporary
1538      * @return <code>false</code> if the focus change request is guaranteed to
1539      *         fail; <code>true</code> if it is likely to succeed
1540      * @see java.awt.Component#requestFocusInWindow()
1541      * @see java.awt.Component#requestFocusInWindow(boolean)
1542      * @since 1.4
1543      */
1544     protected boolean requestFocusInWindow(boolean temporary) {
1545         return super.requestFocusInWindow(temporary);
1546     }
1547 
1548     /**
1549      * Requests that this Component get the input focus, and that this
1550      * Component's top-level ancestor become the focused Window. This component
1551      * must be displayable, visible, and focusable for the request to be
1552      * granted.
1553      * <p>


2578      * calculated return <code>BaselineResizeBehavior.OTHER</code>.  Callers
2579      * should first ask for the baseline using
2580      * <code>getBaseline</code> and if a value &gt;= 0 is returned use
2581      * this method.  It is acceptable for this method to return a
2582      * value other than <code>BaselineResizeBehavior.OTHER</code> even if
2583      * <code>getBaseline</code> returns a value less than 0.
2584      *
2585      * @see #getBaseline(int, int)
2586      * @since 1.6
2587      */
2588     public BaselineResizeBehavior getBaselineResizeBehavior() {
2589         if (ui != null) {
2590             return ui.getBaselineResizeBehavior(this);
2591         }
2592         return BaselineResizeBehavior.OTHER;
2593     }
2594 
2595     /**
2596      * In release 1.4, the focus subsystem was rearchitected.
2597      * For more information, see
2598      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
2599      * How to Use the Focus Subsystem</a>,
2600      * a section in <em>The Java Tutorial</em>.
2601      * <p>
2602      * Requests focus on this <code>JComponent</code>'s
2603      * <code>FocusTraversalPolicy</code>'s default <code>Component</code>.
2604      * If this <code>JComponent</code> is a focus cycle root, then its
2605      * <code>FocusTraversalPolicy</code> is used. Otherwise, the
2606      * <code>FocusTraversalPolicy</code> of this <code>JComponent</code>'s
2607      * focus-cycle-root ancestor is used.
2608      *
2609      * @see java.awt.FocusTraversalPolicy#getDefaultComponent
2610      * @deprecated As of 1.4, replaced by
2611      * <code>FocusTraversalPolicy.getDefaultComponent(Container).requestFocus()</code>
2612      */
2613     @Deprecated
2614     public boolean requestDefaultFocus() {
2615         Container nearestRoot =
2616             (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
2617         if (nearestRoot == null) {
2618             return false;


2969     static boolean processKeyBindingsForAllComponents(KeyEvent e,
2970                                       Container container, boolean pressed) {
2971         while (true) {
2972             if (KeyboardManager.getCurrentManager().fireKeyboardAction(
2973                                 e, pressed, container)) {
2974                 return true;
2975             }
2976             if (container instanceof Popup.HeavyWeightWindow) {
2977                 container = ((Window)container).getOwner();
2978             }
2979             else {
2980                 return false;
2981             }
2982         }
2983     }
2984 
2985     /**
2986      * Registers the text to display in a tool tip.
2987      * The text displays when the cursor lingers over the component.
2988      * <p>
2989      * See <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
2990      * in <em>The Java Tutorial</em>
2991      * for further documentation.
2992      *
2993      * @param text  the string to display; if the text is <code>null</code>,
2994      *              the tool tip is turned off for this component
2995      * @see #TOOL_TIP_TEXT_KEY
2996      * @beaninfo
2997      *   preferred: true
2998      * description: The text to display in a tool tip.
2999      */
3000     public void setToolTipText(String text) {
3001         String oldText = getToolTipText();
3002         putClientProperty(TOOL_TIP_TEXT_KEY, text);
3003         ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
3004         if (text != null) {
3005             if (oldText == null) {
3006                 toolTipManager.registerComponent(this);
3007             }
3008         } else {
3009             toolTipManager.unregisterComponent(this);


3189      * <p>
3190      * If the new {@code TransferHandler} is not {@code null}, this method
3191      * also installs a <b>new</b> {@code DropTarget} on the component to
3192      * activate drop handling through the {@code TransferHandler} and activate
3193      * any built-in support (such as calculating and displaying potential drop
3194      * locations). If you do not wish for this component to respond in any way
3195      * to drops, you can disable drop support entirely either by removing the
3196      * drop target ({@code setDropTarget(null)}) or by de-activating it
3197      * ({@code getDropTaget().setActive(false)}).
3198      * <p>
3199      * If the new {@code TransferHandler} is {@code null}, this method removes
3200      * the drop target.
3201      * <p>
3202      * Under two circumstances, this method does not modify the drop target:
3203      * First, if the existing drop target on this component was explicitly
3204      * set by the developer to a {@code non-null} value. Second, if the
3205      * system property {@code suppressSwingDropSupport} is {@code true}. The
3206      * default value for the system property is {@code false}.
3207      * <p>
3208      * Please see
3209      * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html">
3210      * How to Use Drag and Drop and Data Transfer</a>,
3211      * a section in <em>The Java Tutorial</em>, for more information.
3212      *
3213      * @param newHandler the new {@code TransferHandler}
3214      *
3215      * @see TransferHandler
3216      * @see #getTransferHandler
3217      * @since 1.4
3218      * @beaninfo
3219      *        bound: true
3220      *       hidden: true
3221      *  description: Mechanism for transfer of data to and from the component
3222      */
3223     public void setTransferHandler(TransferHandler newHandler) {
3224         TransferHandler oldHandler = (TransferHandler)getClientProperty(
3225                                       JComponent_TRANSFER_HANDLER);
3226         putClientProperty(JComponent_TRANSFER_HANDLER, newHandler);
3227 
3228         SwingUtilities.installSwingDropTargetAsNecessary(this, newHandler);
3229         firePropertyChange("transferHandler", oldHandler, newHandler);




  61 import javax.swing.event.*;
  62 import javax.swing.plaf.*;
  63 import static javax.swing.ClientPropertyKey.*;
  64 import javax.accessibility.*;
  65 
  66 import sun.swing.SwingUtilities2;
  67 import sun.swing.UIClientPropertyKey;
  68 
  69 /**
  70  * The base class for all Swing components except top-level containers.
  71  * To use a component that inherits from <code>JComponent</code>,
  72  * you must place the component in a containment hierarchy
  73  * whose root is a top-level Swing container.
  74  * Top-level Swing containers --
  75  * such as <code>JFrame</code>, <code>JDialog</code>,
  76  * and <code>JApplet</code> --
  77  * are specialized components
  78  * that provide a place for other Swing components to paint themselves.
  79  * For an explanation of containment hierarchies, see
  80  * <a
  81  href="http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html">Swing Components and the Containment Hierarchy</a>,
  82  * a section in <em>The Java Tutorial</em>.
  83  *
  84  * <p>
  85  * The <code>JComponent</code> class provides:
  86  * <ul>
  87  * <li>The base class for both standard and custom components
  88  *     that use the Swing architecture.
  89  * <li>A "pluggable look and feel" (L&amp;F) that can be specified by the
  90  *     programmer or (optionally) selected by the user at runtime.
  91  *     The look and feel for each component is provided by a
  92  *     <em>UI delegate</em> -- an object that descends from
  93  *     {@link javax.swing.plaf.ComponentUI}.
  94  *     See <a
  95  * href="http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html">How
  96  *     to Set the Look and Feel</a>
  97  *     in <em>The Java Tutorial</em>
  98  *     for more information.
  99  * <li>Comprehensive keystroke handling.
 100  *     See the document <a
 101  * href="http://www.oracle.com/technetwork/java/index.html">Keyboard
 102  *     Bindings in Swing</a>,
 103  *     an article in <em>The Swing Connection</em>,
 104  *     for more information.
 105  * <li>Support for tool tips --
 106  *     short descriptions that pop up when the cursor lingers
 107  *     over a component.
 108  *     See <a
 109  * href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How
 110  *     to Use Tool Tips</a>
 111  *     in <em>The Java Tutorial</em>
 112  *     for more information.
 113  * <li>Support for accessibility.
 114  *     <code>JComponent</code> contains all of the methods in the
 115  *     <code>Accessible</code> interface,
 116  *     but it doesn't actually implement the interface.  That is the
 117  *     responsibility of the individual classes
 118  *     that extend <code>JComponent</code>.
 119  * <li>Support for component-specific properties.
 120  *     With the {@link #putClientProperty}
 121  *     and {@link #getClientProperty} methods,
 122  *     you can associate name-object pairs
 123  *     with any object that descends from <code>JComponent</code>.
 124  * <li>An infrastructure for painting
 125  *     that includes double buffering and support for borders.
 126  *     For more information see <a
 127  * href="http://www.oracle.com/technetwork/java/painting-140037.html#swing">Painting</a> and
 128  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/border.htmll">How
 129  *     to Use Borders</a>,
 130  *     both of which are sections in <em>The Java Tutorial</em>.
 131  * </ul>
 132  * For more information on these subjects, see the
 133  * <a href="package-summary.html#package_description">Swing package description</a>
 134  * and <em>The Java Tutorial</em> section
 135  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/jcomponent.html">The JComponent Class</a>.
 136  * <p>
 137  * <code>JComponent</code> and its subclasses document default values
 138  * for certain properties.  For example, <code>JTable</code> documents the
 139  * default row height as 16.  Each <code>JComponent</code> subclass
 140  * that has a <code>ComponentUI</code> will create the
 141  * <code>ComponentUI</code> as part of its constructor.  In order
 142  * to provide a particular look and feel each
 143  * <code>ComponentUI</code> may set properties back on the
 144  * <code>JComponent</code> that created it.  For example, a custom
 145  * look and feel may require <code>JTable</code>s to have a row
 146  * height of 24. The documented defaults are the value of a property
 147  * BEFORE the <code>ComponentUI</code> has been installed.  If you
 148  * need a specific value for a particular property you should
 149  * explicitly set it.
 150  * <p>
 151  * In release 1.4, the focus subsystem was rearchitected.
 152  * For more information, see
 153  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
 154  * How to Use the Focus Subsystem</a>,
 155  * a section in <em>The Java Tutorial</em>.
 156  * <p>
 157  * <strong>Warning:</strong> Swing is not thread safe. For more
 158  * information see <a
 159  * href="package-summary.html#threading">Swing's Threading
 160  * Policy</a>.
 161  * <p>
 162  * <strong>Warning:</strong>
 163  * Serialized objects of this class will not be compatible with
 164  * future Swing releases. The current serialization support is
 165  * appropriate for short term storage or RMI between applications running
 166  * the same version of Swing.  As of 1.4, support for long term storage
 167  * of all JavaBeans<sup><font size="-2">TM</font></sup>
 168  * has been added to the <code>java.beans</code> package.
 169  * Please see {@link java.beans.XMLEncoder}.
 170  *
 171  * @see KeyStroke
 172  * @see Action
 173  * @see #setBorder


1274      * level print processes. For example, a {@link javax.swing.JTable#print()}
1275      * operation doesn't necessarily result in a continuous rendering of the
1276      * full component, and the return value of this method can change multiple
1277      * times during that operation. It is even possible for the component to be
1278      * painted to the screen while the printing process is ongoing. In such a
1279      * case, the return value of this method is <code>true</code> when, and only
1280      * when, the table is being painted as part of the printing process.
1281      *
1282      * @return true if the current painting operation on this component
1283      *         is part of a print operation
1284      * @see #print
1285      * @since 1.6
1286      */
1287     public final boolean isPaintingForPrint() {
1288         return getFlag(IS_PRINTING);
1289     }
1290 
1291     /**
1292      * In release 1.4, the focus subsystem was rearchitected.
1293      * For more information, see
1294      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1295      * How to Use the Focus Subsystem</a>,
1296      * a section in <em>The Java Tutorial</em>.
1297      * <p>
1298      * Changes this <code>JComponent</code>'s focus traversal keys to
1299      * CTRL+TAB and CTRL+SHIFT+TAB. Also prevents
1300      * <code>SortingFocusTraversalPolicy</code> from considering descendants
1301      * of this JComponent when computing a focus traversal cycle.
1302      *
1303      * @see java.awt.Component#setFocusTraversalKeys
1304      * @see SortingFocusTraversalPolicy
1305      * @deprecated As of 1.4, replaced by
1306      *   <code>Component.setFocusTraversalKeys(int, Set)</code> and
1307      *   <code>Container.setFocusCycleRoot(boolean)</code>.
1308      */
1309     @Deprecated
1310     public boolean isManagingFocus() {
1311         return false;
1312     }
1313 
1314     private void registerNextFocusableComponent() {


1336         Component nextFocusableComponent = getNextFocusableComponent();
1337         if (nextFocusableComponent == null) {
1338             return;
1339         }
1340 
1341         Container nearestRoot =
1342             (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
1343         if (nearestRoot == null) {
1344             return;
1345         }
1346         FocusTraversalPolicy policy = nearestRoot.getFocusTraversalPolicy();
1347         if (policy instanceof LegacyGlueFocusTraversalPolicy) {
1348             ((LegacyGlueFocusTraversalPolicy)policy).
1349                 unsetNextFocusableComponent(this, nextFocusableComponent);
1350         }
1351     }
1352 
1353     /**
1354      * In release 1.4, the focus subsystem was rearchitected.
1355      * For more information, see
1356      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1357      * How to Use the Focus Subsystem</a>,
1358      * a section in <em>The Java Tutorial</em>.
1359      * <p>
1360      * Overrides the default <code>FocusTraversalPolicy</code> for this
1361      * <code>JComponent</code>'s focus traversal cycle by unconditionally
1362      * setting the specified <code>Component</code> as the next
1363      * <code>Component</code> in the cycle, and this <code>JComponent</code>
1364      * as the specified <code>Component</code>'s previous
1365      * <code>Component</code> in the cycle.
1366      *
1367      * @param aComponent the <code>Component</code> that should follow this
1368      *        <code>JComponent</code> in the focus traversal cycle
1369      *
1370      * @see #getNextFocusableComponent
1371      * @see java.awt.FocusTraversalPolicy
1372      * @deprecated As of 1.4, replaced by <code>FocusTraversalPolicy</code>
1373      */
1374     @Deprecated
1375     public void setNextFocusableComponent(Component aComponent) {
1376         boolean displayable = isDisplayable();
1377         if (displayable) {
1378             deregisterNextFocusableComponent();
1379         }
1380         putClientProperty(NEXT_FOCUS, aComponent);
1381         if (displayable) {
1382             registerNextFocusableComponent(aComponent);
1383         }
1384     }
1385 
1386     /**
1387      * In release 1.4, the focus subsystem was rearchitected.
1388      * For more information, see
1389      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1390      * How to Use the Focus Subsystem</a>,
1391      * a section in <em>The Java Tutorial</em>.
1392      * <p>
1393      * Returns the <code>Component</code> set by a prior call to
1394      * <code>setNextFocusableComponent(Component)</code> on this
1395      * <code>JComponent</code>.
1396      *
1397      * @return the <code>Component</code> that will follow this
1398      *        <code>JComponent</code> in the focus traversal cycle, or
1399      *        <code>null</code> if none has been explicitly specified
1400      *
1401      * @see #setNextFocusableComponent
1402      * @deprecated As of 1.4, replaced by <code>FocusTraversalPolicy</code>.
1403      */
1404     @Deprecated
1405     public Component getNextFocusableComponent() {
1406         return (Component)getClientProperty(NEXT_FOCUS);
1407     }
1408 
1409     /**
1410      * Provides a hint as to whether or not this <code>JComponent</code>
1411      * should get focus. This is only a hint, and it is up to consumers that
1412      * are requesting focus to honor this property. This is typically honored
1413      * for mouse operations, but not keyboard operations. For example, look
1414      * and feels could verify this property is true before requesting focus
1415      * during a mouse operation. This would often times be used if you did
1416      * not want a mouse press on a <code>JComponent</code> to steal focus,
1417      * but did want the <code>JComponent</code> to be traversable via the
1418      * keyboard. If you do not want this <code>JComponent</code> focusable at
1419      * all, use the <code>setFocusable</code> method instead.
1420      * <p>
1421      * Please see
1422      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1423      * How to Use the Focus Subsystem</a>,
1424      * a section in <em>The Java Tutorial</em>,
1425      * for more information.
1426      *
1427      * @param requestFocusEnabled indicates whether you want this
1428      *        <code>JComponent</code> to be focusable or not
1429      * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
1430      * @see java.awt.Component#setFocusable
1431      */
1432     public void setRequestFocusEnabled(boolean requestFocusEnabled) {
1433         setFlag(REQUEST_FOCUS_DISABLED, !requestFocusEnabled);
1434     }
1435 
1436     /**
1437      * Returns <code>true</code> if this <code>JComponent</code> should
1438      * get focus; otherwise returns <code>false</code>.
1439      * <p>
1440      * Please see
1441      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1442      * How to Use the Focus Subsystem</a>,
1443      * a section in <em>The Java Tutorial</em>,
1444      * for more information.
1445      *
1446      * @return <code>true</code> if this component should get focus,
1447      *     otherwise returns <code>false</code>
1448      * @see #setRequestFocusEnabled
1449      * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus
1450      *      Specification</a>
1451      * @see java.awt.Component#isFocusable
1452      */
1453     public boolean isRequestFocusEnabled() {
1454         return !getFlag(REQUEST_FOCUS_DISABLED);
1455     }
1456 
1457     /**
1458      * Requests that this <code>Component</code> gets the input focus.
1459      * Refer to {@link java.awt.Component#requestFocus()
1460      * Component.requestFocus()} for a complete description of
1461      * this method.
1462      * <p>
1463      * Note that the use of this method is discouraged because
1464      * its behavior is platform dependent. Instead we recommend the
1465      * use of {@link #requestFocusInWindow() requestFocusInWindow()}.
1466      * If you would like more information on focus, see
1467      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1468      * How to Use the Focus Subsystem</a>,
1469      * a section in <em>The Java Tutorial</em>.
1470      *
1471      * @see java.awt.Component#requestFocusInWindow()
1472      * @see java.awt.Component#requestFocusInWindow(boolean)
1473      * @since 1.4
1474      */
1475     public void requestFocus() {
1476         super.requestFocus();
1477     }
1478 
1479     /**
1480      * Requests that this <code>Component</code> gets the input focus.
1481      * Refer to {@link java.awt.Component#requestFocus(boolean)
1482      * Component.requestFocus(boolean)} for a complete description of
1483      * this method.
1484      * <p>
1485      * Note that the use of this method is discouraged because
1486      * its behavior is platform dependent. Instead we recommend the
1487      * use of {@link #requestFocusInWindow(boolean)
1488      * requestFocusInWindow(boolean)}.
1489      * If you would like more information on focus, see
1490      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1491      * How to Use the Focus Subsystem</a>,
1492      * a section in <em>The Java Tutorial</em>.
1493      *
1494      * @param temporary boolean indicating if the focus change is temporary
1495      * @return <code>false</code> if the focus change request is guaranteed to
1496      *         fail; <code>true</code> if it is likely to succeed
1497      * @see java.awt.Component#requestFocusInWindow()
1498      * @see java.awt.Component#requestFocusInWindow(boolean)
1499      * @since 1.4
1500      */
1501     public boolean requestFocus(boolean temporary) {
1502         return super.requestFocus(temporary);
1503     }
1504 
1505     /**
1506      * Requests that this <code>Component</code> gets the input focus.
1507      * Refer to {@link java.awt.Component#requestFocusInWindow()
1508      * Component.requestFocusInWindow()} for a complete description of
1509      * this method.
1510      * <p>
1511      * If you would like more information on focus, see
1512      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1513      * How to Use the Focus Subsystem</a>,
1514      * a section in <em>The Java Tutorial</em>.
1515      *
1516      * @return <code>false</code> if the focus change request is guaranteed to
1517      *         fail; <code>true</code> if it is likely to succeed
1518      * @see java.awt.Component#requestFocusInWindow()
1519      * @see java.awt.Component#requestFocusInWindow(boolean)
1520      * @since 1.4
1521      */
1522     public boolean requestFocusInWindow() {
1523         return super.requestFocusInWindow();
1524     }
1525 
1526     /**
1527      * Requests that this <code>Component</code> gets the input focus.
1528      * Refer to {@link java.awt.Component#requestFocusInWindow(boolean)
1529      * Component.requestFocusInWindow(boolean)} for a complete description of
1530      * this method.
1531      * <p>
1532      * If you would like more information on focus, see
1533      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
1534      * How to Use the Focus Subsystem</a>,
1535      * a section in <em>The Java Tutorial</em>.
1536      *
1537      * @param temporary boolean indicating if the focus change is temporary
1538      * @return <code>false</code> if the focus change request is guaranteed to
1539      *         fail; <code>true</code> if it is likely to succeed
1540      * @see java.awt.Component#requestFocusInWindow()
1541      * @see java.awt.Component#requestFocusInWindow(boolean)
1542      * @since 1.4
1543      */
1544     protected boolean requestFocusInWindow(boolean temporary) {
1545         return super.requestFocusInWindow(temporary);
1546     }
1547 
1548     /**
1549      * Requests that this Component get the input focus, and that this
1550      * Component's top-level ancestor become the focused Window. This component
1551      * must be displayable, visible, and focusable for the request to be
1552      * granted.
1553      * <p>


2578      * calculated return <code>BaselineResizeBehavior.OTHER</code>.  Callers
2579      * should first ask for the baseline using
2580      * <code>getBaseline</code> and if a value &gt;= 0 is returned use
2581      * this method.  It is acceptable for this method to return a
2582      * value other than <code>BaselineResizeBehavior.OTHER</code> even if
2583      * <code>getBaseline</code> returns a value less than 0.
2584      *
2585      * @see #getBaseline(int, int)
2586      * @since 1.6
2587      */
2588     public BaselineResizeBehavior getBaselineResizeBehavior() {
2589         if (ui != null) {
2590             return ui.getBaselineResizeBehavior(this);
2591         }
2592         return BaselineResizeBehavior.OTHER;
2593     }
2594 
2595     /**
2596      * In release 1.4, the focus subsystem was rearchitected.
2597      * For more information, see
2598      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2599      * How to Use the Focus Subsystem</a>,
2600      * a section in <em>The Java Tutorial</em>.
2601      * <p>
2602      * Requests focus on this <code>JComponent</code>'s
2603      * <code>FocusTraversalPolicy</code>'s default <code>Component</code>.
2604      * If this <code>JComponent</code> is a focus cycle root, then its
2605      * <code>FocusTraversalPolicy</code> is used. Otherwise, the
2606      * <code>FocusTraversalPolicy</code> of this <code>JComponent</code>'s
2607      * focus-cycle-root ancestor is used.
2608      *
2609      * @see java.awt.FocusTraversalPolicy#getDefaultComponent
2610      * @deprecated As of 1.4, replaced by
2611      * <code>FocusTraversalPolicy.getDefaultComponent(Container).requestFocus()</code>
2612      */
2613     @Deprecated
2614     public boolean requestDefaultFocus() {
2615         Container nearestRoot =
2616             (isFocusCycleRoot()) ? this : getFocusCycleRootAncestor();
2617         if (nearestRoot == null) {
2618             return false;


2969     static boolean processKeyBindingsForAllComponents(KeyEvent e,
2970                                       Container container, boolean pressed) {
2971         while (true) {
2972             if (KeyboardManager.getCurrentManager().fireKeyboardAction(
2973                                 e, pressed, container)) {
2974                 return true;
2975             }
2976             if (container instanceof Popup.HeavyWeightWindow) {
2977                 container = ((Window)container).getOwner();
2978             }
2979             else {
2980                 return false;
2981             }
2982         }
2983     }
2984 
2985     /**
2986      * Registers the text to display in a tool tip.
2987      * The text displays when the cursor lingers over the component.
2988      * <p>
2989      * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How to Use Tool Tips</a>
2990      * in <em>The Java Tutorial</em>
2991      * for further documentation.
2992      *
2993      * @param text  the string to display; if the text is <code>null</code>,
2994      *              the tool tip is turned off for this component
2995      * @see #TOOL_TIP_TEXT_KEY
2996      * @beaninfo
2997      *   preferred: true
2998      * description: The text to display in a tool tip.
2999      */
3000     public void setToolTipText(String text) {
3001         String oldText = getToolTipText();
3002         putClientProperty(TOOL_TIP_TEXT_KEY, text);
3003         ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
3004         if (text != null) {
3005             if (oldText == null) {
3006                 toolTipManager.registerComponent(this);
3007             }
3008         } else {
3009             toolTipManager.unregisterComponent(this);


3189      * <p>
3190      * If the new {@code TransferHandler} is not {@code null}, this method
3191      * also installs a <b>new</b> {@code DropTarget} on the component to
3192      * activate drop handling through the {@code TransferHandler} and activate
3193      * any built-in support (such as calculating and displaying potential drop
3194      * locations). If you do not wish for this component to respond in any way
3195      * to drops, you can disable drop support entirely either by removing the
3196      * drop target ({@code setDropTarget(null)}) or by de-activating it
3197      * ({@code getDropTaget().setActive(false)}).
3198      * <p>
3199      * If the new {@code TransferHandler} is {@code null}, this method removes
3200      * the drop target.
3201      * <p>
3202      * Under two circumstances, this method does not modify the drop target:
3203      * First, if the existing drop target on this component was explicitly
3204      * set by the developer to a {@code non-null} value. Second, if the
3205      * system property {@code suppressSwingDropSupport} is {@code true}. The
3206      * default value for the system property is {@code false}.
3207      * <p>
3208      * Please see
3209      * <a href="http://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
3210      * How to Use Drag and Drop and Data Transfer</a>,
3211      * a section in <em>The Java Tutorial</em>, for more information.
3212      *
3213      * @param newHandler the new {@code TransferHandler}
3214      *
3215      * @see TransferHandler
3216      * @see #getTransferHandler
3217      * @since 1.4
3218      * @beaninfo
3219      *        bound: true
3220      *       hidden: true
3221      *  description: Mechanism for transfer of data to and from the component
3222      */
3223     public void setTransferHandler(TransferHandler newHandler) {
3224         TransferHandler oldHandler = (TransferHandler)getClientProperty(
3225                                       JComponent_TRANSFER_HANDLER);
3226         putClientProperty(JComponent_TRANSFER_HANDLER, newHandler);
3227 
3228         SwingUtilities.installSwingDropTargetAsNecessary(this, newHandler);
3229         firePropertyChange("transferHandler", oldHandler, newHandler);