javax.swing

Class ScrollPaneLayout

  • All Implemented Interfaces:
    LayoutManager, Serializable, ScrollPaneConstants
    Direct Known Subclasses:
    ScrollPaneLayout.UIResource

    public class ScrollPaneLayout
    extends Object
    implements LayoutManager, ScrollPaneConstants, Serializable
    The layout manager used by JScrollPane. JScrollPaneLayout is responsible for nine components: a viewport, two scrollbars, a row header, a column header, and four "corner" components.

    Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

    See Also:
    JScrollPane, JViewport
    • Constructor Detail

      • ScrollPaneLayout

        public ScrollPaneLayout()
    • Method Detail

      • syncWithScrollPane

        public void syncWithScrollPane(JScrollPane sp)
        This method is invoked after the ScrollPaneLayout is set as the LayoutManager of a JScrollPane. It initializes all of the internal fields that are ordinarily set by addLayoutComponent. For example:
         ScrollPaneLayout mySPLayout = new ScrollPanelLayout() {
             public void layoutContainer(Container p) {
                 super.layoutContainer(p);
                 // do some extra work here ...
             }
         };
         scrollpane.setLayout(mySPLayout):
         
      • addSingletonComponent

        protected Component addSingletonComponent(Component oldC,
                                      Component newC)
        Removes an existing component. When a new component, such as the left corner, or vertical scrollbar, is added, the old one, if it exists, must be removed.

        This method returns newC. If oldC is not equal to newC and is non-null, it will be removed from its parent.

        Parameters:
        oldC - the Component to replace
        newC - the Component to add
        Returns:
        the newC
      • addLayoutComponent

        public void addLayoutComponent(String s,
                              Component c)
        Adds the specified component to the layout. The layout is identified using one of:
        • ScrollPaneConstants.VIEWPORT
        • ScrollPaneConstants.VERTICAL_SCROLLBAR
        • ScrollPaneConstants.HORIZONTAL_SCROLLBAR
        • ScrollPaneConstants.ROW_HEADER
        • ScrollPaneConstants.COLUMN_HEADER
        • ScrollPaneConstants.LOWER_LEFT_CORNER
        • ScrollPaneConstants.LOWER_RIGHT_CORNER
        • ScrollPaneConstants.UPPER_LEFT_CORNER
        • ScrollPaneConstants.UPPER_RIGHT_CORNER
        Specified by:
        addLayoutComponent in interface LayoutManager
        Parameters:
        s - the component identifier
        c - the the component to be added
        Throws:
        IllegalArgumentException - if s is an invalid key
      • removeLayoutComponent

        public void removeLayoutComponent(Component c)
        Removes the specified component from the layout.
        Specified by:
        removeLayoutComponent in interface LayoutManager
        Parameters:
        c - the component to remove
      • getVerticalScrollBarPolicy

        public int getVerticalScrollBarPolicy()
        Returns the vertical scrollbar-display policy.
        Returns:
        an integer giving the display policy
        See Also:
        setVerticalScrollBarPolicy(int)
      • setVerticalScrollBarPolicy

        public void setVerticalScrollBarPolicy(int x)
        Sets the vertical scrollbar-display policy. The options are:
        • ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED
        • ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER
        • ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
        Note: Applications should use the JScrollPane version of this method. It only exists for backwards compatibility with the Swing 1.0.2 (and earlier) versions of this class.
        Parameters:
        x - an integer giving the display policy
        Throws:
        IllegalArgumentException - if x is an invalid vertical scroll bar policy, as listed above
      • getHorizontalScrollBarPolicy

        public int getHorizontalScrollBarPolicy()
        Returns the horizontal scrollbar-display policy.
        Returns:
        an integer giving the display policy
        See Also:
        setHorizontalScrollBarPolicy(int)
      • setHorizontalScrollBarPolicy

        public void setHorizontalScrollBarPolicy(int x)
        Sets the horizontal scrollbar-display policy. The options are:
        • ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
        • ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
        • ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
        Note: Applications should use the JScrollPane version of this method. It only exists for backwards compatibility with the Swing 1.0.2 (and earlier) versions of this class.
        Parameters:
        x - an int giving the display policy
        Throws:
        IllegalArgumentException - if x is not a valid horizontal scrollbar policy, as listed above
      • getViewport

        public JViewport getViewport()
        Returns the JViewport object that displays the scrollable contents.
        Returns:
        the JViewport object that displays the scrollable contents
        See Also:
        JScrollPane.getViewport()
      • getHorizontalScrollBar

        public JScrollBar getHorizontalScrollBar()
        Returns the JScrollBar object that handles horizontal scrolling.
        Returns:
        the JScrollBar object that handles horizontal scrolling
        See Also:
        JScrollPane.getHorizontalScrollBar()
      • getVerticalScrollBar

        public JScrollBar getVerticalScrollBar()
        Returns the JScrollBar object that handles vertical scrolling.
        Returns:
        the JScrollBar object that handles vertical scrolling
        See Also:
        JScrollPane.getVerticalScrollBar()
      • getRowHeader

        public JViewport getRowHeader()
        Returns the JViewport object that is the row header.
        Returns:
        the JViewport object that is the row header
        See Also:
        JScrollPane.getRowHeader()
      • getColumnHeader

        public JViewport getColumnHeader()
        Returns the JViewport object that is the column header.
        Returns:
        the JViewport object that is the column header
        See Also:
        JScrollPane.getColumnHeader()
      • preferredLayoutSize

        public Dimension preferredLayoutSize(Container parent)
        The preferred size of a ScrollPane is the size of the insets, plus the preferred size of the viewport, plus the preferred size of the visible headers, plus the preferred size of the scrollbars that will appear given the current view and the current scrollbar displayPolicies.

        Note that the rowHeader is calculated as part of the preferred width and the colHeader is calculated as part of the preferred size.

        Specified by:
        preferredLayoutSize in interface LayoutManager
        Parameters:
        parent - the Container that will be laid out
        Returns:
        a Dimension object specifying the preferred size of the viewport and any scrollbars
        See Also:
        ViewportLayout, LayoutManager
      • minimumLayoutSize

        public Dimension minimumLayoutSize(Container parent)
        The minimum size of a ScrollPane is the size of the insets plus minimum size of the viewport, plus the scrollpane's viewportBorder insets, plus the minimum size of the visible headers, plus the minimum size of the scrollbars whose displayPolicy isn't NEVER.
        Specified by:
        minimumLayoutSize in interface LayoutManager
        Parameters:
        parent - the Container that will be laid out
        Returns:
        a Dimension object specifying the minimum size
        See Also:
        LayoutManager.preferredLayoutSize(java.awt.Container)
      • layoutContainer

        public void layoutContainer(Container parent)
        Lays out the scrollpane. The positioning of components depends on the following constraints:
        • The row header, if present and visible, gets its preferred width and the viewport's height.
        • The column header, if present and visible, gets its preferred height and the viewport's width.
        • If a vertical scrollbar is needed, i.e. if the viewport's extent height is smaller than its view height or if the displayPolicy is ALWAYS, it's treated like the row header with respect to its dimensions and is made visible.
        • If a horizontal scrollbar is needed, it is treated like the column header (see the paragraph above regarding the vertical scrollbar).
        • If the scrollpane has a non-null viewportBorder, then space is allocated for that.
        • The viewport gets the space available after accounting for the previous constraints.
        • The corner components, if provided, are aligned with the ends of the scrollbars and headers. If there is a vertical scrollbar, the right corners appear; if there is a horizontal scrollbar, the lower corners appear; a row header gets left corners, and a column header gets upper corners.
        Specified by:
        layoutContainer in interface LayoutManager
        Parameters:
        parent - the Container to lay out
      • getViewportBorderBounds

        @Deprecated
        public Rectangle getViewportBorderBounds(JScrollPane scrollpane)
        Deprecated. As of JDK version Swing1.1 replaced by JScrollPane.getViewportBorderBounds().
        Returns the bounds of the border around the specified scroll pane's viewport.
        Returns:
        the size and position of the viewport border

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