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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  61  * has been added to the <code>java.beans</code> package.
  62  * Please see {@link java.beans.XMLEncoder}.
  63  *
  64  * <p>
  65  * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html">How to Use Combo Boxes</a>
  66  * in <a href="http://docs.oracle.com/javase/tutorial/"><em>The Java Tutorial</em></a>
  67  * for further information.
  68  * <p>
  69  * @see ComboBoxModel
  70  * @see DefaultComboBoxModel
  71  *
  72  * @param <E> the type of the elements of this combo box
  73  *
  74  * @beaninfo
  75  *   attribute: isContainer false
  76  * description: A combination of a text field and a drop-down list.
  77  *
  78  * @author Arnaud Weber
  79  * @author Mark Davidson
  80  */

  81 public class JComboBox<E> extends JComponent
  82 implements ItemSelectable,ListDataListener,ActionListener, Accessible {
  83     /**
  84      * @see #getUIClassID
  85      * @see #readObject
  86      */
  87     private static final String uiClassID = "ComboBoxUI";
  88 
  89     /**
  90      * This protected field is implementation specific. Do not access directly
  91      * or override. Use the accessor methods instead.
  92      *
  93      * @see #getModel
  94      * @see #setModel
  95      */
  96     protected ComboBoxModel<E>    dataModel;
  97     /**
  98      * This protected field is implementation specific. Do not access directly
  99      * or override. Use the accessor methods instead.
 100      *


1595         if ( accessibleContext == null ) {
1596             accessibleContext = new AccessibleJComboBox();
1597         }
1598         return accessibleContext;
1599     }
1600 
1601     /**
1602      * This class implements accessibility support for the
1603      * <code>JComboBox</code> class.  It provides an implementation of the
1604      * Java Accessibility API appropriate to Combo Box user-interface elements.
1605      * <p>
1606      * <strong>Warning:</strong>
1607      * Serialized objects of this class will not be compatible with
1608      * future Swing releases. The current serialization support is
1609      * appropriate for short term storage or RMI between applications running
1610      * the same version of Swing.  As of 1.4, support for long term storage
1611      * of all JavaBeans&trade;
1612      * has been added to the <code>java.beans</code> package.
1613      * Please see {@link java.beans.XMLEncoder}.
1614      */

1615     protected class AccessibleJComboBox extends AccessibleJComponent
1616     implements AccessibleAction, AccessibleSelection {
1617 
1618 
1619         private JList popupList; // combo box popup list
1620         private Accessible previousSelectedAccessible = null;
1621 
1622         /**
1623          * Returns an AccessibleJComboBox instance
1624          * @since 1.4
1625          */
1626         public AccessibleJComboBox() {
1627             // set the combo box editor's accessible name and description
1628             JComboBox.this.addPropertyChangeListener(new AccessibleJComboBoxPropertyChangeListener());
1629             setEditorNameAndDescription();
1630 
1631             // Get the popup list
1632             Accessible a = getUI().getAccessibleChild(JComboBox.this, 0);
1633             if (a instanceof javax.swing.plaf.basic.ComboPopup) {
1634                 // Listen for changes to the popup menu selection.


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  61  * has been added to the <code>java.beans</code> package.
  62  * Please see {@link java.beans.XMLEncoder}.
  63  *
  64  * <p>
  65  * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html">How to Use Combo Boxes</a>
  66  * in <a href="http://docs.oracle.com/javase/tutorial/"><em>The Java Tutorial</em></a>
  67  * for further information.
  68  * <p>
  69  * @see ComboBoxModel
  70  * @see DefaultComboBoxModel
  71  *
  72  * @param <E> the type of the elements of this combo box
  73  *
  74  * @beaninfo
  75  *   attribute: isContainer false
  76  * description: A combination of a text field and a drop-down list.
  77  *
  78  * @author Arnaud Weber
  79  * @author Mark Davidson
  80  */
  81 @SuppressWarnings("serial") // Same-version serialization only
  82 public class JComboBox<E> extends JComponent
  83 implements ItemSelectable,ListDataListener,ActionListener, Accessible {
  84     /**
  85      * @see #getUIClassID
  86      * @see #readObject
  87      */
  88     private static final String uiClassID = "ComboBoxUI";
  89 
  90     /**
  91      * This protected field is implementation specific. Do not access directly
  92      * or override. Use the accessor methods instead.
  93      *
  94      * @see #getModel
  95      * @see #setModel
  96      */
  97     protected ComboBoxModel<E>    dataModel;
  98     /**
  99      * This protected field is implementation specific. Do not access directly
 100      * or override. Use the accessor methods instead.
 101      *


1596         if ( accessibleContext == null ) {
1597             accessibleContext = new AccessibleJComboBox();
1598         }
1599         return accessibleContext;
1600     }
1601 
1602     /**
1603      * This class implements accessibility support for the
1604      * <code>JComboBox</code> class.  It provides an implementation of the
1605      * Java Accessibility API appropriate to Combo Box user-interface elements.
1606      * <p>
1607      * <strong>Warning:</strong>
1608      * Serialized objects of this class will not be compatible with
1609      * future Swing releases. The current serialization support is
1610      * appropriate for short term storage or RMI between applications running
1611      * the same version of Swing.  As of 1.4, support for long term storage
1612      * of all JavaBeans&trade;
1613      * has been added to the <code>java.beans</code> package.
1614      * Please see {@link java.beans.XMLEncoder}.
1615      */
1616     @SuppressWarnings("serial") // Same-version serialization only
1617     protected class AccessibleJComboBox extends AccessibleJComponent
1618     implements AccessibleAction, AccessibleSelection {
1619 
1620 
1621         private JList popupList; // combo box popup list
1622         private Accessible previousSelectedAccessible = null;
1623 
1624         /**
1625          * Returns an AccessibleJComboBox instance
1626          * @since 1.4
1627          */
1628         public AccessibleJComboBox() {
1629             // set the combo box editor's accessible name and description
1630             JComboBox.this.addPropertyChangeListener(new AccessibleJComboBoxPropertyChangeListener());
1631             setEditorNameAndDescription();
1632 
1633             // Get the popup list
1634             Accessible a = getUI().getAccessibleChild(JComboBox.this, 0);
1635             if (a instanceof javax.swing.plaf.basic.ComboPopup) {
1636                 // Listen for changes to the popup menu selection.