⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcombobox.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* JComboBox.java --   Copyright (C) 2002, 2004, 2005  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.ItemSelectable;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.Vector;import javax.accessibility.Accessible;import javax.accessibility.AccessibleAction;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleSelection;import javax.swing.event.ListDataEvent;import javax.swing.event.ListDataListener;import javax.swing.event.PopupMenuListener;import javax.swing.event.PopupMenuEvent;import javax.swing.plaf.ComboBoxUI;/** * A component that allows a user to select any item in its list and * displays the selected item to the user. JComboBox also can show/hide a * popup menu containing its list of item whenever the mouse is pressed * over it. * * @author Andrew Selkirk * @author Olga Rodimina * @author Robert Schuster */public class JComboBox extends JComponent implements ItemSelectable,                                                     ListDataListener,                                                     ActionListener,                                                     Accessible{  private static final long serialVersionUID = 5654585963292734470L;  /**   * Classes implementing this interface are   * responsible for matching key characters typed by the user with combo   * box's items.   */  public static interface KeySelectionManager  {    int selectionForKey(char aKey, ComboBoxModel aModel);  }  /**   * Maximum number of rows that should be visible by default  in the   * JComboBox's popup   */  private static final int DEFAULT_MAXIMUM_ROW_COUNT = 8;  /**   * Data model used by JComboBox to keep track of its list data and currently   * selected element in the list.   */  protected ComboBoxModel dataModel;  /**   * Renderer renders(paints) every object in the combo box list in its   * associated list cell. This ListCellRenderer is used only when  this   * JComboBox is uneditable.   */  protected ListCellRenderer renderer;  /**   * Editor that is responsible for editing an object in a combo box list.   */  protected ComboBoxEditor editor;  /**   * Number of rows that will be visible in the JComboBox's popup.   */  protected int maximumRowCount;  /**   * This field indicates if textfield of this JComboBox is editable or not.   */  protected boolean isEditable;  /**   * This field is reference to the current selection of the combo box.   */  protected Object selectedItemReminder;  /**   * keySelectionManager   */  protected KeySelectionManager keySelectionManager;  /**   * This actionCommand is used in ActionEvent that is fired to JComboBox's   * ActionListeneres.   */  protected String actionCommand;  /**   * This property indicates if heavyweight popup or lightweight popup will be   * used to diplay JComboBox's elements.   */  protected boolean lightWeightPopupEnabled;  /**   * The action taken when new item is selected in the JComboBox   */  private Action action;  /**   * since 1.4  If this field is set then comboBox's display area for the   * selected item  will be set by default to this value.   */  private Object prototypeDisplayValue;  /**   * Constructs JComboBox object with specified data model for it.   * <p>Note that the JComboBox will not change the value that   * is preselected by your ComboBoxModel implementation.</p>   *   * @param model Data model that will be used by this JComboBox to keep track   *        of its list of items.   */  public JComboBox(ComboBoxModel model)  {    setEditable(false);    setEnabled(true);    setMaximumRowCount(DEFAULT_MAXIMUM_ROW_COUNT);    setModel(model);    setActionCommand("comboBoxChanged");    lightWeightPopupEnabled = true;    isEditable = false;    updateUI();  }  /**   * Constructs JComboBox with specified list of items.   *   * @param itemArray array containing list of items for this JComboBox   */  public JComboBox(Object[] itemArray)  {    this(new DefaultComboBoxModel(itemArray));        if (itemArray.length > 0)       setSelectedIndex(0);  }  /**   * Constructs JComboBox object with specified list of items.   *   * @param itemVector vector containing list of items for this JComboBox.   */  public JComboBox(Vector itemVector)  {    this(new DefaultComboBoxModel(itemVector));    if (itemVector.size() > 0)      setSelectedIndex(0);  }  /**   * Constructor. Creates new empty JComboBox. ComboBox's data model is set to   * DefaultComboBoxModel.   */  public JComboBox()  {    this(new DefaultComboBoxModel());  }  /**   * This method returns true JComboBox is editable and false otherwise   *   * @return boolean true if JComboBox is editable and false otherwise   */  public boolean isEditable()  {    return isEditable;  }  /*   * This method adds ancestor listener to this JComboBox.   */  protected void installAncestorListener()  {    /* FIXME: Need to implement.     *     * Need to add ancestor listener to this JComboBox. This listener     * should close combo box's popup list of items whenever it     * receives an AncestorEvent.     */  }  /**   * Set the "UI" property of the combo box, which is a look and feel class   * responsible for handling comboBox's input events and painting it.   *   * @param ui The new "UI" property   */  public void setUI(ComboBoxUI ui)  {    super.setUI(ui);  }  /**   * This method sets this comboBox's UI to the UIManager's default for the   * current look and feel.   */  public void updateUI()  {    setUI((ComboBoxUI) UIManager.getUI(this));    invalidate();  }  /**   * This method returns the String identifier for the UI class to the used   * with the JComboBox.   *   * @return The String identifier for the UI class.   */  public String getUIClassID()  {    return "ComboBoxUI";  }  /**   * This method returns the UI used to display the JComboBox.   *   * @return The UI used to display the JComboBox.   */  public ComboBoxUI getUI()  {    return (ComboBoxUI) ui;  }  /**   * Set the data model for this JComboBox. This un-registers all  listeners   * associated with the current model, and re-registers them with the new   * model.   *   * @param newDataModel The new data model for this JComboBox   */  public void setModel(ComboBoxModel newDataModel)  {    // dataModel is null if it this method is called from inside the constructors.    if (dataModel != null)      {        // Prevents unneccessary updates.        if (dataModel == newDataModel)          return;        // Removes itself (as DataListener) from the to-be-replaced model.        dataModel.removeListDataListener(this);      }        /* Adds itself as a DataListener to the new model.     * It is intentioned that this operation will fail with a NullPointerException if the     * caller delivered a null argument.     */    newDataModel.addListDataListener(this);    // Stores old data model for event notification.    ComboBoxModel oldDataModel = dataModel;    dataModel = newDataModel;    selectedItemReminder = newDataModel.getSelectedItem();        // Notifies the listeners of the model change.    firePropertyChange("model", oldDataModel, dataModel);  }  /**   * This method returns data model for this comboBox.   *   * @return ComboBoxModel containing items for this combo box.   */  public ComboBoxModel getModel()  {    return dataModel;  }  /**   * This method sets JComboBox's popup to be either lightweight or   * heavyweight. If 'enabled' is true then lightweight popup is used and   * heavyweight otherwise. By default lightweight popup is used to display   * this JComboBox's elements.   *   * @param enabled indicates if lightweight popup or heavyweight popup should   *        be used to display JComboBox's elements.   */  public void setLightWeightPopupEnabled(boolean enabled)  {    lightWeightPopupEnabled = enabled;  }  /**   * This method returns whether popup menu that is used to display list of   * combo box's item is lightWeight or not.   *   * @return boolean true if popup menu is lightweight and false otherwise.   */  public boolean isLightWeightPopupEnabled()  {    return lightWeightPopupEnabled;  }  /**   * This method sets editability of the combo box. If combo box  is editable   * the user can choose component from the combo box list by typing   * component's name in the editor(JTextfield by default).  Otherwise if not   * editable, the user should use the list to choose   the component. This   * method fires PropertyChangeEvents to JComboBox's registered   * PropertyChangeListeners to indicate that 'editable' property of the   * JComboBox has changed.   *   * @param editable indicates if the JComboBox's textfield should be editable   *        or not.   */  public void setEditable(boolean editable)  {    if (isEditable != editable)      {        isEditable = editable;        firePropertyChange("editable", !isEditable, isEditable);      }  }  /**   * Sets number of rows that should be visible in this JComboBox's popup. If   * this JComboBox's popup has more elements that maximum number or rows   * then popup will have a scroll pane to allow users to view other   * elements.   *   * @param rowCount number of rows that will be visible in JComboBox's popup.   */  public void setMaximumRowCount(int rowCount)  {    if (maximumRowCount != rowCount)      {        int oldMaximumRowCount = maximumRowCount;        maximumRowCount = rowCount;        firePropertyChange("maximumRowCount", oldMaximumRowCount,                           maximumRowCount);      }  }  /**   * This method returns number of rows visible in the JComboBox's list of   * items.   *   * @return int maximun number of visible rows in the JComboBox's list.   */  public int getMaximumRowCount()  {    return maximumRowCount;  }  /**   * This method sets cell renderer for this JComboBox that will be used to   * paint combo box's items. The Renderer should only be used only when   * JComboBox is not editable.  In the case when JComboBox is editable  the   * editor must be used.  This method also fires PropertyChangeEvent when   * cellRendered for this JComboBox has changed.   *   * @param aRenderer cell renderer that will be used by this JComboBox to   *        paint its elements.   */  public void setRenderer(ListCellRenderer aRenderer)  {    if (renderer != aRenderer)      {        ListCellRenderer oldRenderer = renderer;        renderer = aRenderer;        firePropertyChange("renderer", oldRenderer, renderer);      }  }  /**   * This method returns renderer responsible for rendering selected item in   * the combo box   *   * @return ListCellRenderer   */  public ListCellRenderer getRenderer()  {    return renderer;  }  /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -