javax.swing.plaf.basic

Class BasicListUI

  • Direct Known Subclasses:
    SynthListUI

    public class BasicListUI
    extends ListUI
    An extensible implementation of ListUI.

    BasicListUI instances cannot be shared between multiple lists.

    • Constructor Detail

      • BasicListUI

        public BasicListUI()
    • Method Detail

      • getPreferredSize

        public Dimension getPreferredSize(JComponent c)
        The preferredSize of the list depends upon the layout orientation.
        Layout OrientationPreferred Size
        JList.VERTICAL The preferredSize of the list is total height of the rows and the maximum width of the cells. If JList.fixedCellHeight is specified then the total height of the rows is just (cellVerticalMargins + fixedCellHeight) * model.getSize() where rowVerticalMargins is the space we allocate for drawing the yellow focus outline. Similarly if fixedCellWidth is specified then we just use that.
        JList.VERTICAL_WRAP If the visible row count is greater than zero, the preferredHeight is the maximum cell height * visibleRowCount. If the visible row count is <= 0, the preferred height is either the current height of the list, or the maximum cell height, whichever is bigger. The preferred width is than the maximum cell width * number of columns needed. Where the number of columns needs is list.height / max cell height. Max cell height is either the fixed cell height, or is determined by iterating through all the cells to find the maximum height from the ListCellRenderer.
        JList.HORIZONTAL_WRAP If the visible row count is greater than zero, the preferredHeight is the maximum cell height * adjustedRowCount. Where visibleRowCount is used to determine the number of columns. Because this lays out horizontally the number of rows is then determined from the column count. For example, lets say you have a model with 10 items and the visible row count is 8. The number of columns needed to display this is 2, but you no longer need 8 rows to display this, you only need 5, thus the adjustedRowCount is 5.

        If the visible row count is <= 0, the preferred height is dictated by the number of columns, which will be as many as can fit in the width of the JList (width / max cell width), with at least one column. The preferred height then becomes the model size / number of columns * maximum cell height. Max cell height is either the fixed cell height, or is determined by iterating through all the cells to find the maximum height from the ListCellRenderer.

        Eerste pagina van API Java Inhoudsopgave Haut

        The above specifies the raw preferred width and height. The resulting preferred width is the above width + insets.left + insets.right and the resulting preferred height is the above height + insets.top + insets.bottom. Where the Insets are determined from list.getInsets().
        Overrides:
        getPreferredSize in class ComponentUI
        Parameters:
        c - The JList component.
        Returns:
        The total size of the list.
        See Also:
        JComponent.getPreferredSize(), LayoutManager.preferredLayoutSize(java.awt.Container)
      • selectPreviousIndex

        protected void selectPreviousIndex()
        Selected the previous row and force it to be visible.
        See Also:
        JList.ensureIndexIsVisible(int)
      • installKeyboardActions

        protected void installKeyboardActions()
        Registers the keyboard bindings on the JList that the BasicListUI is associated with. This method is called at installUI() time.
        See Also:
        installUI(javax.swing.JComponent)
      • uninstallKeyboardActions

        protected void uninstallKeyboardActions()
        Unregisters keyboard actions installed from installKeyboardActions. This method is called at uninstallUI() time - subclassess should ensure that all of the keyboard actions registered at installUI time are removed here.
        See Also:
        installUI(javax.swing.JComponent)
      • uninstallListeners

        protected void uninstallListeners()
        Removes the listeners from the JList, its model, and its selectionModel. All of the listener fields, are reset to null here. This method is called at uninstallUI() time, it should be kept in sync with installListeners.
        See Also:
        uninstallUI(javax.swing.JComponent), installListeners()
      • installDefaults

        protected void installDefaults()
        Initializes list properties such as font, foreground, and background, and adds the CellRendererPane. The font, foreground, and background properties are only set if their current value is either null or a UIResource, other properties are set if the current value is null.
        See Also:
        uninstallDefaults(), installUI(javax.swing.JComponent), CellRendererPane
      • uninstallUI

        public void uninstallUI(JComponent c)
        Uninitializes this.list by calling uninstallListeners(), uninstallKeyboardActions(), and uninstallDefaults() in order. Sets this.list to null.
        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:
        uninstallListeners(), uninstallKeyboardActions(), uninstallDefaults()
      • createUI

        public static ComponentUI createUI(JComponent list)
        Returns a new instance of BasicListUI. BasicListUI delegates are allocated one per JList.
        Returns:
        A new ListUI implementation for the Windows look and feel.
      • locationToIndex

        public int locationToIndex(JList list,
                          Point location)
        Returns the cell index in the specified JList closest to the given location in the list's coordinate system. To determine if the cell actually contains the specified location, compare the point against the cell's bounds, as provided by getCellBounds. This method returns -1 if the list's model is empty.
        Specified by:
        locationToIndex in class ListUI
        Parameters:
        list - the list
        location - the coordinates of the point
        Returns:
        the cell index closest to the given location, or -1
        Throws:
        NullPointerException - if location is null
      • indexToLocation

        public Point indexToLocation(JList list,
                            int index)
        Returns the origin in the given JList, of the specified item, in the list's coordinate system. Returns null if the index isn't valid.
        Specified by:
        indexToLocation in class ListUI
        Parameters:
        list - the list
        index - the cell index
        Returns:
        the origin of the cell, or null
      • getCellBounds

        public Rectangle getCellBounds(JList list,
                              int index1,
                              int index2)
        Returns the bounding rectangle, in the given list's coordinate system, for the range of cells specified by the two indices. The indices can be supplied in any order.

        If the smaller index is outside the list's range of cells, this method returns null. If the smaller index is valid, but the larger index is outside the list's range, the bounds of just the first index is returned. Otherwise, the bounds of the valid range is returned.

        Specified by:
        getCellBounds in class ListUI
        Parameters:
        list - the list
        index1 - the first index in the range
        index2 - the second index in the range
        Returns:
        the bounding rectangle for the range of cells, or null
      • convertYToRow

        protected int convertYToRow(int y0)
        Convert the JList relative coordinate to the row that contains it, based on the current layout. If y0 doesn't fall within any row, return -1.
        Returns:
        The row that contains y0, or -1.
        See Also:
        getRowHeight(int), updateLayoutState()
      • convertRowToY

        protected int convertRowToY(int row)
        Return the JList relative Y coordinate of the origin of the specified row or -1 if row isn't valid.
        Returns:
        The Y coordinate of the origin of row, or -1.
        See Also:
        getRowHeight(int), updateLayoutState()
      • maybeUpdateLayoutState

        protected void maybeUpdateLayoutState()
        If updateLayoutStateNeeded is non zero, call updateLayoutState() and reset updateLayoutStateNeeded. This method should be called by methods before doing any computation based on the geometry of the list. For example it's the first call in paint() and getPreferredSize().
        See Also:
        updateLayoutState()
      • updateLayoutState

        protected void updateLayoutState()
        Recompute the value of cellHeight or cellHeights based and cellWidth, based on the current font and the current values of fixedCellWidth, fixedCellHeight, and prototypeCellValue.
        See Also:
        maybeUpdateLayoutState()
      • createMouseInputListener

        protected MouseInputListener createMouseInputListener()
        Creates a delegate that implements MouseInputListener. The delegate is added to the corresponding java.awt.Component listener lists at installUI() time. Subclasses can override this method to return a custom MouseInputListener, e.g.
         class MyListUI extends BasicListUI {
            protected MouseInputListener createMouseInputListener() {
                return new MyMouseInputHandler();
            }
            public class MyMouseInputHandler extends MouseInputHandler {
                public void mouseMoved(MouseEvent e) {
                    // do some extra work when the mouse moves
                    super.mouseMoved(e);
                }
            }
         }
         
        See Also:
        BasicListUI.MouseInputHandler, installUI(javax.swing.JComponent)
      • createFocusListener

        protected FocusListener createFocusListener()
      • createListSelectionListener

        protected ListSelectionListener createListSelectionListener()
        Creates an instance of ListSelectionHandler that's added to the JLists by selectionModel as needed. Subclasses can override this method to return a custom ListSelectionListener, e.g.
         class MyListUI extends BasicListUI {
            protected ListSelectionListener createListSelectionListener() {
                return new MySelectionListener();
            }
            public class MySelectionListener extends ListSelectionHandler {
                public void valueChanged(ListSelectionEvent e) {
                    // do some extra work when the selection changes
                    super.valueChange(e);
                }
            }
         }
         
        See Also:
        BasicListUI.ListSelectionHandler, installUI(javax.swing.JComponent)
      • createListDataListener

        protected ListDataListener createListDataListener()
        Creates an instance of ListDataListener that's added to the JLists by model as needed. Subclasses can override this method to return a custom ListDataListener, e.g.
         class MyListUI extends BasicListUI {
            protected ListDataListener createListDataListener() {
                return new MyListDataListener();
            }
            public class MyListDataListener extends ListDataHandler {
                public void contentsChanged(ListDataEvent e) {
                    // do some extra work when the models contents change
                    super.contentsChange(e);
                }
            }
         }
         
        See Also:
        ListDataListener, JList.getModel(), installUI(javax.swing.JComponent)
      • createPropertyChangeListener

        protected PropertyChangeListener createPropertyChangeListener()
        Creates an instance of PropertyChangeHandler that's added to the JList by installUI(). Subclasses can override this method to return a custom PropertyChangeListener, e.g.
         class MyListUI extends BasicListUI {
            protected PropertyChangeListener createPropertyChangeListener() {
                return new MyPropertyChangeListener();
            }
            public class MyPropertyChangeListener extends PropertyChangeHandler {
                public void propertyChange(PropertyChangeEvent e) {
                    if (e.getPropertyName().equals("model")) {
                        // do some extra work when the model changes
                    }
                    super.propertyChange(e);
                }
            }
         }
         
        See Also:
        PropertyChangeListener, installUI(javax.swing.JComponent)

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/basiclistui.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