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://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html">How to Use Key Bindings</a>,
 102  *     an article in <em>The Java Tutorial</em>,

 103  *     for more information.
 104  * <li>Support for tool tips --
 105  *     short descriptions that pop up when the cursor lingers
 106  *     over a component.
 107  *     See <a
 108  * href="http://docs.oracle.com/javase/tutorial/uiswing/components/tooltip.html">How
 109  *     to Use Tool Tips</a>
 110  *     in <em>The Java Tutorial</em>
 111  *     for more information.
 112  * <li>Support for accessibility.
 113  *     <code>JComponent</code> contains all of the methods in the
 114  *     <code>Accessible</code> interface,
 115  *     but it doesn't actually implement the interface.  That is the
 116  *     responsibility of the individual classes
 117  *     that extend <code>JComponent</code>.
 118  * <li>Support for component-specific properties.
 119  *     With the {@link #putClientProperty}
 120  *     and {@link #getClientProperty} methods,
 121  *     you can associate name-object pairs
 122  *     with any object that descends from <code>JComponent</code>.
 123  * <li>An infrastructure for painting
 124  *     that includes double buffering and support for borders.
 125  *     For more information see <a
 126  * href="http://www.oracle.com/technetwork/java/painting-140037.html#swing">Painting</a> and
 127  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/border.htmll">How
 128  *     to Use Borders</a>,
 129  *     both of which are sections in <em>The Java Tutorial</em>.
 130  * </ul>
 131  * For more information on these subjects, see the
 132  * <a href="package-summary.html#package_description">Swing package description</a>
 133  * and <em>The Java Tutorial</em> section
 134  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/jcomponent.html">The JComponent Class</a>.
 135  * <p>
 136  * <code>JComponent</code> and its subclasses document default values
 137  * for certain properties.  For example, <code>JTable</code> documents the
 138  * default row height as 16.  Each <code>JComponent</code> subclass
 139  * that has a <code>ComponentUI</code> will create the
 140  * <code>ComponentUI</code> as part of its constructor.  In order
 141  * to provide a particular look and feel each
 142  * <code>ComponentUI</code> may set properties back on the
 143  * <code>JComponent</code> that created it.  For example, a custom
 144  * look and feel may require <code>JTable</code>s to have a row
 145  * height of 24. The documented defaults are the value of a property
 146  * BEFORE the <code>ComponentUI</code> has been installed.  If you
 147  * need a specific value for a particular property you should
 148  * explicitly set it.
 149  * <p>
 150  * In release 1.4, the focus subsystem was rearchitected.
 151  * For more information, see
 152  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
 153  * How to Use the Focus Subsystem</a>,
 154  * a section in <em>The Java Tutorial</em>.
 155  * <p>
 156  * <strong>Warning:</strong> Swing is not thread safe. For more
 157  * information see <a
 158  * href="package-summary.html#threading">Swing's Threading
 159  * Policy</a>.
 160  * <p>
 161  * <strong>Warning:</strong>
 162  * Serialized objects of this class will not be compatible with
 163  * future Swing releases. The current serialization support is
 164  * appropriate for short term storage or RMI between applications running
 165  * the same version of Swing.  As of 1.4, support for long term storage
 166  * of all JavaBeans<sup><font size="-2">TM</font></sup>
 167  * has been added to the <code>java.beans</code> package.
 168  * Please see {@link java.beans.XMLEncoder}.
 169  *
 170  * @see KeyStroke
 171  * @see Action
 172  * @see #setBorder


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


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


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


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


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