javax.swing.plaf.basic

Class BasicComboBoxUI

  • Direct Known Subclasses:
    MetalComboBoxUI, SynthComboBoxUI

    public class BasicComboBoxUI
    extends ComboBoxUI
    Basic UI implementation for JComboBox.

    The combo box is a compound component which means that it is an agregate of many simpler components. This class creates and manages the listeners on the combo box and the combo box model. These listeners update the user interface in response to changes in the properties and state of the combo box.

    All event handling is handled by listener classes created with the createxxxListener() methods and internal classes. You can change the behavior of this class by overriding the createxxxListener() methods and supplying your own event listeners or subclassing from the ones supplied in this class.

    For adding specific actions, overide installKeyboardActions to add actions in response to KeyStroke bindings. See the article Keyboard Bindings in Swing at The Swing Connection.

    • Field Detail

      • hasFocus

        protected boolean hasFocus
        This protected field is implementation specific. Do not access directly or override.
      • listBox

        protected JList listBox
      • arrowButton

        protected JButton arrowButton
      • keyListener

        protected KeyListener keyListener
        This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.
        See Also:
        createKeyListener()
      • focusListener

        protected FocusListener focusListener
        This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.
        See Also:
        createFocusListener()
      • itemListener

        protected ItemListener itemListener
        This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.
        See Also:
        createItemListener()
      • popupKeyListener

        protected KeyListener popupKeyListener
      • listDataListener

        protected ListDataListener listDataListener
        This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.
        See Also:
        createListDataListener()
      • isMinimumSizeDirty

        protected boolean isMinimumSizeDirty
      • cachedMinimumSize

        protected Dimension cachedMinimumSize
      • squareButton

        protected boolean squareButton
        Indicates whether or not the combo box button should be square. If square, then the width and height are equal, and are both set to the height of the combo minus appropriate insets.
        Since:
        1.7
      • padding

        protected Insets padding
        If specified, these insets act as padding around the cell renderer when laying out and painting the "selected" item in the combo box. These insets add to those specified by the cell renderer.
        Since:
        1.7
    • Constructor Detail

      • BasicComboBoxUI

        public BasicComboBoxUI()
    • Method Detail

      • installUI

        public void installUI(JComponent c)
        Description copied from class: ComponentUI
        Configures the specified component appropriately for the look and feel. This method is invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:
        1. Install default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
        2. Install a LayoutManager on the component if necessary.
        3. Create/add any required sub-components to the component.
        4. Create/install event listeners on the component.
        5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
        6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
        7. Initialize any appropriate instance data.
        Overrides:
        installUI in class ComponentUI
        Parameters:
        c - the component where this UI delegate is being installed
        See Also:
        ComponentUI.uninstallUI(javax.swing.JComponent), JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()
      • uninstallUI

        public void uninstallUI(JComponent c)
        Description copied from class: ComponentUI
        Reverses configuration which was done on the specified component during installUI. This method is invoked when this UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in installUI, being careful to leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:
        1. Remove any UI-set borders from the component.
        2. Remove any UI-set layout managers on the component.
        3. Remove any UI-added sub-components from the component.
        4. Remove any UI-added event/property listeners from the component.
        5. Remove any UI-installed keyboard UI from the component.
        6. Nullify any allocated instance data objects to allow for GC.
        Overrides:
        uninstallUI in class ComponentUI
        Parameters:
        c - the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
        See Also:
        ComponentUI.installUI(javax.swing.JComponent), JComponent.updateUI()
      • installDefaults

        protected void installDefaults()
        Installs the default colors, default font, default renderer, and default editor into the JComboBox.
      • installListeners

        protected void installListeners()
        Creates and installs listeners for the combo box and its model. This method is called when the UI is installed.
      • uninstallDefaults

        protected void uninstallDefaults()
        Uninstalls the default colors, default font, default renderer, and default editor from the combo box.
      • uninstallListeners

        protected void uninstallListeners()
        Removes the installed listeners from the combo box and its model. The number and types of listeners removed and in this method should be the same that was added in installListeners
      • createPopup

        protected ComboPopup createPopup()
        Creates the popup portion of the combo box.
        Returns:
        an instance of ComboPopup
        See Also:
        ComboPopup
      • createKeyListener

        protected KeyListener createKeyListener()
        Creates a KeyListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.
        Returns:
        an instance KeyListener or null
      • createFocusListener

        protected FocusListener createFocusListener()
        Creates a FocusListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.
        Returns:
        an instance of a FocusListener or null
      • createListDataListener

        protected ListDataListener createListDataListener()
        Creates a list data listener which will be added to the ComboBoxModel. If this method returns null then it will not be added to the combo box model.
        Returns:
        an instance of a ListDataListener or null
      • createItemListener

        protected ItemListener createItemListener()
        Creates an ItemListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

        Subclasses may override this method to return instances of their own ItemEvent handlers.

        Returns:
        an instance of an ItemListener or null
      • createPropertyChangeListener

        protected PropertyChangeListener createPropertyChangeListener()
        Creates a PropertyChangeListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.
        Returns:
        an instance of a PropertyChangeListener or null
      • createLayoutManager

        protected LayoutManager createLayoutManager()
        Creates a layout manager for managing the components which make up the combo box.
        Returns:
        an instance of a layout manager
      • createEditor

        protected ComboBoxEditor createEditor()
        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 setEditor.
        Returns:
        a ComboBoxEditor used for the combo box
        See Also:
        JComboBox.setEditor(javax.swing.ComboBoxEditor)
      • installComponents

        protected void installComponents()
        Creates and initializes the components which make up the aggregate combo box. This method is called as part of the UI installation process.
      • uninstallComponents

        protected void uninstallComponents()
        The aggregate components which compise the combo box are unregistered and uninitialized. This method is called as part of the UI uninstallation process.
      • removeEditor

        public void removeEditor()
        This public method is implementation specific and should be private. do not call or override.
        See Also:
        addEditor()
      • configureEditor

        protected void configureEditor()
        This protected method is implementation specific and should be private. do not call or override.
        See Also:
        addEditor()
      • unconfigureEditor

        protected void unconfigureEditor()
        This protected method is implementation specific and should be private. Do not call or override.
        See Also:
        addEditor()
      • configureArrowButton

        public void configureArrowButton()
        This public method is implementation specific and should be private. Do not call or override.
        See Also:
        createArrowButton()
      • unconfigureArrowButton

        public void unconfigureArrowButton()
        This public method is implementation specific and should be private. Do not call or override.
        See Also:
        createArrowButton()
      • createArrowButton

        protected JButton createArrowButton()
        Creates a button which will be used as the control to show or hide the popup portion of the combo box.
        Returns:
        a button which represents the popup control
      • isFocusTraversable

        public boolean isFocusTraversable(JComboBox c)
        Determines if the JComboBox is focus traversable. If the JComboBox is editable this returns false, otherwise it returns true.
        Specified by:
        isFocusTraversable in class ComboBoxUI
      • paint

        public void paint(Graphics g,
                 JComponent c)
        Description copied from class: ComponentUI
        Paints the specified component appropriately for the look and feel. This method is invoked from the ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified Graphics object to render the content of the component.
        Overrides:
        paint in class ComponentUI
        Parameters:
        g - the Graphics context in which to paint
        c - the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
        See Also:
        ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)
      • getPreferredSize

        public Dimension getPreferredSize(JComponent c)
        Description copied from class: ComponentUI
        Returns the specified component's preferred size appropriate for the look and feel. If null is returned, the preferred size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method returns null.
        Overrides:
        getPreferredSize in class ComponentUI
        Parameters:
        c - the component whose preferred size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
        See Also:
        JComponent.getPreferredSize(), LayoutManager.preferredLayoutSize(java.awt.Container)
      • getMaximumSize

        public Dimension getMaximumSize(JComponent c)
        Description copied from class: ComponentUI
        Returns the specified component's maximum size appropriate for the look and feel. If null is returned, the maximum size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method invokes getPreferredSize and returns that value.
        Overrides:
        getMaximumSize in class ComponentUI
        Parameters:
        c - the component whose maximum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
        Returns:
        a Dimension object or null
        See Also:
        JComponent.getMaximumSize(), LayoutManager2.maximumLayoutSize(java.awt.Container)
      • getAccessibleChildrenCount

        public int getAccessibleChildrenCount(JComponent c)
        Description copied from class: ComponentUI
        Returns the number of accessible children in the object. If all of the children of this object implement Accessible, this method should return the number of children of this object. UIs might wish to override this if they present areas on the screen that can be viewed as components, but actual components are not used for presenting those areas. Note: As of v1.3, it is recommended that developers call Component.AccessibleAWTComponent.getAccessibleChildrenCount() instead of this method.
        Overrides:
        getAccessibleChildrenCount in class ComponentUI
        Returns:
        the number of accessible children in the object
        See Also:
        ComponentUI.getAccessibleChild(javax.swing.JComponent, int)
      • getAccessibleChild

        public Accessible getAccessibleChild(JComponent c,
                                    int i)
        Description copied from class: ComponentUI
        Returns the ith Accessible child of the object. UIs might need to override this if they present areas on the screen that can be viewed as components, but actual components are not used for presenting those areas.

        Note: As of v1.3, it is recommended that developers call Component.AccessibleAWTComponent.getAccessibleChild() instead of this method.

        Overrides:
        getAccessibleChild in class ComponentUI
        i - zero-based index of child
        Returns:
        the ith Accessible child of the object
        See Also:
        ComponentUI.getAccessibleChildrenCount(javax.swing.JComponent)
      • isNavigationKey

        protected boolean isNavigationKey(int keyCode)
        Returns whether or not the supplied keyCode maps to a key that is used for navigation. This is used for optimizing key input by only passing non- navigation keys to the type-ahead mechanism. Subclasses should override this if they change the navigation keys.
      • selectNextPossibleValue

        protected void selectNextPossibleValue()
        Selects the next item in the list. It won't change the selection if the currently selected item is already the last item.
      • selectPreviousPossibleValue

        protected void selectPreviousPossibleValue()
        Selects the previous item in the list. It won't change the selection if the currently selected item is already the first item.
      • toggleOpenClose

        protected void toggleOpenClose()
        Hides the popup if it is showing and shows the popup if it is hidden.
      • rectangleForCurrentValue

        protected Rectangle rectangleForCurrentValue()
        Returns the area that is reserved for drawing the currently selected item.
      • getInsets

        protected Insets getInsets()
        Gets the insets from the JComboBox.
      • paintCurrentValue

        public void paintCurrentValue(Graphics g,
                             Rectangle bounds,
                             boolean hasFocus)
        Paints the currently selected item.
      • paintCurrentValueBackground

        public void paintCurrentValueBackground(Graphics g,
                                       Rectangle bounds,
                                       boolean hasFocus)
        Paints the background of the currently selected item.
      • getDefaultSize

        protected Dimension getDefaultSize()
        Return the default size of an empty display area of the combo box using the current renderer and font.
        Returns:
        the size of an empty display area
        See Also:
        getDisplaySize()
      • getDisplaySize

        protected Dimension getDisplaySize()
        Returns the calculated size of the display area. The display area is the portion of the combo box in which the selected item is displayed. This method will use the prototype display value if it has been set.

        For combo boxes with a non trivial number of items, it is recommended to use a prototype display value to significantly speed up the display size calculation.

        Returns:
        the size of the display area calculated from the combo box items
        See Also:
        JComboBox.setPrototypeDisplayValue(E)
      • getSizeForComponent

        protected Dimension getSizeForComponent(Component comp)
        Returns the size a component would have if used as a cell renderer.
        Parameters:
        comp - a Component to check
        Returns:
        size of the component
        Since:
        1.7
      • installKeyboardActions

        protected void installKeyboardActions()
        Adds keyboard actions to the JComboBox. Actions on enter and esc are already supplied. Add more actions as you need them.
      • uninstallKeyboardActions

        protected void uninstallKeyboardActions()
        Removes the focus InputMap and ActionMap.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/swing/plaf/basic/basiccomboboxui.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut