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

📄 basiccomboboxui.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	}        if ( comboBox.getModel() != null ) {            if ( listDataListener != null ) {                comboBox.getModel().removeListDataListener( listDataListener );            }        }    }    /**     * Creates the popup portion of the combo box.     *     * @return an instance of <code>ComboPopup</code>     * @see ComboPopup     */    protected ComboPopup createPopup() {        return new BasicComboPopup( comboBox );    }    /**     * Creates a <code>KeyListener</code> which will be added to the     * combo box. If this method returns null then it will not be added     * to the combo box.     *      * @return an instance <code>KeyListener</code> or null     */    protected KeyListener createKeyListener() {        return getHandler();    }     /**     * Creates a <code>FocusListener</code> which will be added to the combo box.     * If this method returns null then it will not be added to the combo box.     *     * @return an instance of a <code>FocusListener</code> or null     */    protected FocusListener createFocusListener() {        return getHandler();    }    /**     * Creates a list data listener which will be added to the     * <code>ComboBoxModel</code>. If this method returns null then     * it will not be added to the combo box model.     *     * @return an instance of a <code>ListDataListener</code> or null     */    protected ListDataListener createListDataListener() {        return getHandler();    }    /**     * Creates an <code>ItemListener</code> which will be added to the      * combo box. If this method returns null then it will not      * be added to the combo box.     * <p>     * Subclasses may override this method to return instances of their own     * ItemEvent handlers.     *     * @return an instance of an <code>ItemListener</code> or null     */    protected ItemListener createItemListener() {        return null;    }    /**     * Creates a <code>PropertyChangeListener</code> which will be added to     * the combo box. If this method returns null then it will not     * be added to the combo box.     *      * @return an instance of a <code>PropertyChangeListener</code> or null     */    protected PropertyChangeListener createPropertyChangeListener() {        return getHandler();    }    /**     * Creates a layout manager for managing the components which make up the      * combo box.     *      * @return an instance of a layout manager     */    protected LayoutManager createLayoutManager() {        return getHandler();    }    /**     * Creates the default renderer that will be used in a non-editiable combo      * box. A default renderer will used only if a renderer has not been      * explicitly set with <code>setRenderer</code>.     *      * @return a <code>ListCellRender</code> used for the combo box     * @see javax.swing.JComboBox#setRenderer     */    protected ListCellRenderer createRenderer() {        return new BasicComboBoxRenderer.UIResource();    }    /**     * Creates the default editor that will be used in editable combo boxes.       * A default editor will be used only if an editor has not been      * explicitly set with <code>setEditor</code>.     *     * @return a <code>ComboBoxEditor</code> used for the combo box     * @see javax.swing.JComboBox#setEditor     */    protected ComboBoxEditor createEditor() {        return new BasicComboBoxEditor.UIResource();    }    /**     * Returns the shared listener.     */    private Handler getHandler() {        if (handler == null) {            handler = new Handler();        }        return handler;    }    //    // end UI Initialization    //======================    //======================    // begin Inner classes    //    /**     * This listener checks to see if the key event isn't a navigation key.  If     * it finds a key event that wasn't a navigation key it dispatches it to     * JComboBox.selectWithKeyChar() so that it can do type-ahead.     *     * This public inner class should be treated as protected.      * Instantiate it only within subclasses of      * <code>BasicComboBoxUI</code>.     */    public class KeyHandler extends KeyAdapter {        public void keyPressed( KeyEvent e ) {            getHandler().keyPressed(e);        }    }    /**     * This listener hides the popup when the focus is lost.  It also repaints     * when focus is gained or lost.     *     * This public inner class should be treated as protected.      * Instantiate it only within subclasses of      * <code>BasicComboBoxUI</code>.     */    public class FocusHandler implements FocusListener {        public void focusGained( FocusEvent e ) {            getHandler().focusGained(e);        }        public void focusLost( FocusEvent e ) {            getHandler().focusLost(e);        }    }    /**     * This listener watches for changes in the      * <code>ComboBoxModel</code>.     * <p>     * This public inner class should be treated as protected.      * Instantiate it only within subclasses of      * <code>BasicComboBoxUI</code>.     *     * @see #createListDataListener     */    public class ListDataHandler implements ListDataListener {        public void contentsChanged( ListDataEvent e ) {            getHandler().contentsChanged(e);	}        public void intervalAdded( ListDataEvent e ) {            getHandler().intervalAdded(e);        }        public void intervalRemoved( ListDataEvent e ) {            getHandler().intervalRemoved(e);        }    }    /**     * This listener watches for changes to the selection in the      * combo box.     * <p>     * This public inner class should be treated as protected.      * Instantiate it only within subclasses of      * <code>BasicComboBoxUI</code>.     *     * @see #createItemListener     */    public class ItemHandler implements ItemListener {	// This class used to implement behavior which is now redundant.        public void itemStateChanged(ItemEvent e) {}    }    /**     * This listener watches for bound properties that have changed in the     * combo box.      * <p>     * Subclasses which wish to listen to combo box property changes should     * call the superclass methods to ensure that the combo box ui correctly      * handles property changes.     * <p>     * This public inner class should be treated as protected.      * Instantiate it only within subclasses of      * <code>BasicComboBoxUI</code>.     *      * @see #createPropertyChangeListener     */    public class PropertyChangeHandler implements PropertyChangeListener {        public void propertyChange(PropertyChangeEvent e) {            getHandler().propertyChange(e);        }    }    // Syncronizes the ToolTip text for the components within the combo box to be the     // same value as the combo box ToolTip text.    private void updateToolTipTextForChildren() {        Component[] children = comboBox.getComponents();        for ( int i = 0; i < children.length; ++i ) {            if ( children[i] instanceof JComponent ) {                ((JComponent)children[i]).setToolTipText( comboBox.getToolTipText() );            }        }    }    /**     * This layout manager handles the 'standard' layout of combo boxes.  It puts     * the arrow button to the right and the editor to the left.  If there is no     * editor it still keeps the arrow button to the right.     *     * This public inner class should be treated as protected.      * Instantiate it only within subclasses of      * <code>BasicComboBoxUI</code>.     */    public class ComboBoxLayoutManager implements LayoutManager {        public void addLayoutComponent(String name, Component comp) {}        public void removeLayoutComponent(Component comp) {}        public Dimension preferredLayoutSize(Container parent) {            return getHandler().preferredLayoutSize(parent);        }        public Dimension minimumLayoutSize(Container parent) {            return getHandler().minimumLayoutSize(parent);        }        public void layoutContainer(Container parent) {            getHandler().layoutContainer(parent);        }    }    //    // end Inner classes    //====================    //===============================    // begin Sub-Component Management    //    /**     * Creates and initializes the components which make up the     * aggregate combo box. This method is called as part of the UI     * installation process.     */    protected void installComponents() {        arrowButton = createArrowButton();        comboBox.add( arrowButton );        if (arrowButton != null)  {            configureArrowButton();        }        if ( comboBox.isEditable() ) {            addEditor();        }        comboBox.add( currentValuePane );    }    /**     * The aggregate components which compise the combo box are      * unregistered and uninitialized. This method is called as part of the     * UI uninstallation process.     */    protected void uninstallComponents() {        if ( arrowButton != null ) {            unconfigureArrowButton();        }        if ( editor != null ) {            unconfigureEditor();        }        comboBox.removeAll(); // Just to be safe.        arrowButton = null;    }    /**     * This public method is implementation specific and should be private.     * do not call or override. To implement a specific editor create a     * custom <code>ComboBoxEditor</code>     *     * @see #createEditor     * @see javax.swing.JComboBox#setEditor     * @see javax.swing.ComboBoxEditor     */    public void addEditor() {        removeEditor();        editor = comboBox.getEditor().getEditorComponent();        if ( editor != null ) {            configureEditor();             comboBox.add(editor);            if(comboBox.isFocusOwner()) {                // Switch focus to the editor component                editor.requestFocusInWindow();            }        }    }    /**     * This public method is implementation specific and should be private.     * do not call or override.      *     * @see #addEditor     */    public void removeEditor() {        if ( editor != null ) {            unconfigureEditor();            comboBox.remove( editor );	    editor = null;        }    }    /**     * This protected method is implementation specific and should be private.     * do not call or override.     *      * @see #addEditor     */    protected void configureEditor() {        // Should be in the same state as the combobox        editor.setEnabled(comboBox.isEnabled());        editor.setFocusable(comboBox.isFocusable());        editor.setFont( comboBox.getFont() );        if (focusListener != null) {            editor.addFocusListener(focusListener);        }	editor.addFocusListener( getHandler() );	comboBox.getEditor().addActionListener(getHandler());        if(editor instanceof JComponent) {            ((JComponent)editor).putClientProperty("doNotCancelPopup",                                                   HIDE_POPUP_KEY);            ((JComponent)editor).setInheritsPopupMenu(true);        }        comboBox.configureEditor(comboBox.getEditor(),comboBox.getSelectedItem());    }    /**     * This protected method is implementation specific and should be private.     * Do not call or override.     *      * @see #addEditor     */

⌨️ 快捷键说明

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