BasicScrollPaneUI (Java Platform SE 8 ) (original) (raw)
- javax.swing.plaf.ComponentUI
- javax.swing.plaf.ScrollPaneUI
- javax.swing.plaf.basic.BasicScrollPaneUI
- javax.swing.plaf.ScrollPaneUI
All Implemented Interfaces:
ScrollPaneConstants
Direct Known Subclasses:
MetalScrollPaneUI, SynthScrollPaneUI
public class BasicScrollPaneUI
extends ScrollPaneUI
implements ScrollPaneConstants
A default L&F implementation of ScrollPaneUI.
Nested Class Summary
Nested Classes
Modifier and Type Class Description class BasicScrollPaneUI.HSBChangeListener Horizontal scrollbar listener. protected class BasicScrollPaneUI.MouseWheelHandler MouseWheelHandler is an inner class which implements the MouseWheelListener interface. class BasicScrollPaneUI.PropertyChangeHandler class BasicScrollPaneUI.ViewportChangeHandler Listener for viewport events. class BasicScrollPaneUI.VSBChangeListener Vertical scrollbar listener. Field Summary
Fields
Modifier and Type Field Description protected ChangeListener hsbChangeListener protected JScrollPane scrollpane protected PropertyChangeListener spPropertyChangeListener protected ChangeListener viewportChangeListener protected ChangeListener vsbChangeListener * ### Fields inherited from interface javax.swing.[ScrollPaneConstants](../../../../javax/swing/ScrollPaneConstants.html "interface in javax.swing") `[COLUMN_HEADER](../../../../javax/swing/ScrollPaneConstants.html#COLUMN%5FHEADER), [HORIZONTAL_SCROLLBAR](../../../../javax/swing/ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR), [HORIZONTAL_SCROLLBAR_ALWAYS](../../../../javax/swing/ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR%5FALWAYS), [HORIZONTAL_SCROLLBAR_AS_NEEDED](../../../../javax/swing/ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR%5FAS%5FNEEDED), [HORIZONTAL_SCROLLBAR_NEVER](../../../../javax/swing/ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR%5FNEVER), [HORIZONTAL_SCROLLBAR_POLICY](../../../../javax/swing/ScrollPaneConstants.html#HORIZONTAL%5FSCROLLBAR%5FPOLICY), [LOWER_LEADING_CORNER](../../../../javax/swing/ScrollPaneConstants.html#LOWER%5FLEADING%5FCORNER), [LOWER_LEFT_CORNER](../../../../javax/swing/ScrollPaneConstants.html#LOWER%5FLEFT%5FCORNER), [LOWER_RIGHT_CORNER](../../../../javax/swing/ScrollPaneConstants.html#LOWER%5FRIGHT%5FCORNER), [LOWER_TRAILING_CORNER](../../../../javax/swing/ScrollPaneConstants.html#LOWER%5FTRAILING%5FCORNER), [ROW_HEADER](../../../../javax/swing/ScrollPaneConstants.html#ROW%5FHEADER), [UPPER_LEADING_CORNER](../../../../javax/swing/ScrollPaneConstants.html#UPPER%5FLEADING%5FCORNER), [UPPER_LEFT_CORNER](../../../../javax/swing/ScrollPaneConstants.html#UPPER%5FLEFT%5FCORNER), [UPPER_RIGHT_CORNER](../../../../javax/swing/ScrollPaneConstants.html#UPPER%5FRIGHT%5FCORNER), [UPPER_TRAILING_CORNER](../../../../javax/swing/ScrollPaneConstants.html#UPPER%5FTRAILING%5FCORNER), [VERTICAL_SCROLLBAR](../../../../javax/swing/ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR), [VERTICAL_SCROLLBAR_ALWAYS](../../../../javax/swing/ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR%5FALWAYS), [VERTICAL_SCROLLBAR_AS_NEEDED](../../../../javax/swing/ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR%5FAS%5FNEEDED), [VERTICAL_SCROLLBAR_NEVER](../../../../javax/swing/ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR%5FNEVER), [VERTICAL_SCROLLBAR_POLICY](../../../../javax/swing/ScrollPaneConstants.html#VERTICAL%5FSCROLLBAR%5FPOLICY), [VIEWPORT](../../../../javax/swing/ScrollPaneConstants.html#VIEWPORT)`
Constructor Summary
Constructors
Constructor Description BasicScrollPaneUI() Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type Method Description protected ChangeListener createHSBChangeListener() protected MouseWheelListener createMouseWheelListener() Creates an instance of MouseWheelListener, which is added to the JScrollPane by installUI(). protected PropertyChangeListener createPropertyChangeListener() Creates an instance of PropertyChangeListener that's added to the JScrollPane by installUI(). static ComponentUI createUI(JComponent x) protected ChangeListener createViewportChangeListener() protected ChangeListener createVSBChangeListener() int getBaseline(JComponent c, int width, int height) Returns the baseline. Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) Returns an enum indicating how the baseline of the component changes as the size changes. Dimension getMaximumSize(JComponent c) Returns the specified component's maximum size appropriate for the look and feel. protected void installDefaults(JScrollPane scrollpane) protected void installKeyboardActions(JScrollPane c) protected void installListeners(JScrollPane c) void installUI(JComponent x) Configures the specified component appropriately for the look and feel. void paint(Graphics g,JComponent c) Paints the specified component appropriately for the look and feel. protected void syncScrollPaneWithViewport() protected void uninstallDefaults(JScrollPane c) protected void uninstallKeyboardActions(JScrollPane c) protected void uninstallListeners(JComponent c) void uninstallUI(JComponent c) Reverses configuration which was done on the specified component duringinstallUI. protected void updateColumnHeader(PropertyChangeEvent e) protected void updateRowHeader(PropertyChangeEvent e) protected void updateScrollBarDisplayPolicy(PropertyChangeEvent e) protected void updateViewport(PropertyChangeEvent e) * ### Methods inherited from class javax.swing.plaf.[ComponentUI](../../../../javax/swing/plaf/ComponentUI.html "class in javax.swing.plaf") `[contains](../../../../javax/swing/plaf/ComponentUI.html#contains-javax.swing.JComponent-int-int-), [getAccessibleChild](../../../../javax/swing/plaf/ComponentUI.html#getAccessibleChild-javax.swing.JComponent-int-), [getAccessibleChildrenCount](../../../../javax/swing/plaf/ComponentUI.html#getAccessibleChildrenCount-javax.swing.JComponent-), [getMinimumSize](../../../../javax/swing/plaf/ComponentUI.html#getMinimumSize-javax.swing.JComponent-), [getPreferredSize](../../../../javax/swing/plaf/ComponentUI.html#getPreferredSize-javax.swing.JComponent-), [update](../../../../javax/swing/plaf/ComponentUI.html#update-java.awt.Graphics-javax.swing.JComponent-)` * ### Methods inherited from class java.lang.[Object](../../../../java/lang/Object.html "class in java.lang") `[clone](../../../../java/lang/Object.html#clone--), [equals](../../../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../../../java/lang/Object.html#finalize--), [getClass](../../../../java/lang/Object.html#getClass--), [hashCode](../../../../java/lang/Object.html#hashCode--), [notify](../../../../java/lang/Object.html#notify--), [notifyAll](../../../../java/lang/Object.html#notifyAll--), [toString](../../../../java/lang/Object.html#toString--), [wait](../../../../java/lang/Object.html#wait--), [wait](../../../../java/lang/Object.html#wait-long-), [wait](../../../../java/lang/Object.html#wait-long-int-)`
Field Detail
* #### scrollpane protected [JScrollPane](../../../../javax/swing/JScrollPane.html "class in javax.swing") scrollpane * #### vsbChangeListener protected [ChangeListener](../../../../javax/swing/event/ChangeListener.html "interface in javax.swing.event") vsbChangeListener * #### hsbChangeListener protected [ChangeListener](../../../../javax/swing/event/ChangeListener.html "interface in javax.swing.event") hsbChangeListener * #### viewportChangeListener protected [ChangeListener](../../../../javax/swing/event/ChangeListener.html "interface in javax.swing.event") viewportChangeListener * #### spPropertyChangeListener protected [PropertyChangeListener](../../../../java/beans/PropertyChangeListener.html "interface in java.beans") spPropertyChangeListener
Constructor Detail
* #### BasicScrollPaneUI public BasicScrollPaneUI()
Method Detail
* #### createUI public static [ComponentUI](../../../../javax/swing/plaf/ComponentUI.html "class in javax.swing.plaf") createUI([JComponent](../../../../javax/swing/JComponent.html "class in javax.swing") x) * #### paint public void paint([Graphics](../../../../java/awt/Graphics.html "class in java.awt") g, [JComponent](../../../../javax/swing/JComponent.html "class in javax.swing") c) 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](../../../../javax/swing/plaf/ComponentUI.html#paint-java.awt.Graphics-javax.swing.JComponent-)` in class `[ComponentUI](../../../../javax/swing/plaf/ComponentUI.html "class in javax.swing.plaf")` 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)](../../../../javax/swing/plaf/ComponentUI.html#update-java.awt.Graphics-javax.swing.JComponent-) * #### getMaximumSize public [Dimension](../../../../java/awt/Dimension.html "class in java.awt") getMaximumSize([JComponent](../../../../javax/swing/JComponent.html "class in javax.swing") c) 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](../../../../javax/swing/plaf/ComponentUI.html#getMaximumSize-javax.swing.JComponent-)` in class `[ComponentUI](../../../../javax/swing/plaf/ComponentUI.html "class in javax.swing.plaf")` 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: new Dimension(Short.MAX\_VALUE, Short.MAX\_VALUE) See Also: [JComponent.getMaximumSize()](../../../../javax/swing/JComponent.html#getMaximumSize--), [LayoutManager2.maximumLayoutSize(java.awt.Container)](../../../../java/awt/LayoutManager2.html#maximumLayoutSize-java.awt.Container-) * #### installDefaults protected void installDefaults([JScrollPane](../../../../javax/swing/JScrollPane.html "class in javax.swing") scrollpane) * #### installListeners protected void installListeners([JScrollPane](../../../../javax/swing/JScrollPane.html "class in javax.swing") c) * #### installKeyboardActions protected void installKeyboardActions([JScrollPane](../../../../javax/swing/JScrollPane.html "class in javax.swing") c) * #### installUI public void installUI([JComponent](../../../../javax/swing/JComponent.html "class in javax.swing") x) 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](../../../../javax/swing/plaf/ComponentUI.html#installUI-javax.swing.JComponent-)` in class `[ComponentUI](../../../../javax/swing/plaf/ComponentUI.html "class in javax.swing.plaf")` Parameters: `x` \- the component where this UI delegate is being installed See Also: [ComponentUI.uninstallUI(javax.swing.JComponent)](../../../../javax/swing/plaf/ComponentUI.html#uninstallUI-javax.swing.JComponent-), [JComponent.setUI(javax.swing.plaf.ComponentUI)](../../../../javax/swing/JComponent.html#setUI-javax.swing.plaf.ComponentUI-), [JComponent.updateUI()](../../../../javax/swing/JComponent.html#updateUI--) * #### uninstallDefaults protected void uninstallDefaults([JScrollPane](../../../../javax/swing/JScrollPane.html "class in javax.swing") c) * #### uninstallListeners protected void uninstallListeners([JComponent](../../../../javax/swing/JComponent.html "class in javax.swing") c) * #### uninstallKeyboardActions protected void uninstallKeyboardActions([JScrollPane](../../../../javax/swing/JScrollPane.html "class in javax.swing") c) * #### uninstallUI public void uninstallUI([JComponent](../../../../javax/swing/JComponent.html "class in javax.swing") c) 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](../../../../javax/swing/plaf/ComponentUI.html#uninstallUI-javax.swing.JComponent-)` in class `[ComponentUI](../../../../javax/swing/plaf/ComponentUI.html "class in javax.swing.plaf")` 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)](../../../../javax/swing/plaf/ComponentUI.html#installUI-javax.swing.JComponent-), [JComponent.updateUI()](../../../../javax/swing/JComponent.html#updateUI--) * #### syncScrollPaneWithViewport protected void syncScrollPaneWithViewport() * #### getBaseline public int getBaseline([JComponent](../../../../javax/swing/JComponent.html "class in javax.swing") c, int width, int height) Returns the baseline. Overrides: `[getBaseline](../../../../javax/swing/plaf/ComponentUI.html#getBaseline-javax.swing.JComponent-int-int-)` in class `[ComponentUI](../../../../javax/swing/plaf/ComponentUI.html "class in javax.swing.plaf")` Parameters: `c` \- `JComponent` baseline is being requested for `width` \- the width to get the baseline for `height` \- the height to get the baseline for Returns: baseline or a value < 0 indicating there is no reasonable baseline Throws: `[NullPointerException](../../../../java/lang/NullPointerException.html "class in java.lang")` \- if `c` is `null` `[IllegalArgumentException](../../../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if width or height is < 0 Since: 1.6 See Also: [JComponent.getBaseline(int, int)](../../../../javax/swing/JComponent.html#getBaseline-int-int-) * #### getBaselineResizeBehavior public [Component.BaselineResizeBehavior](../../../../java/awt/Component.BaselineResizeBehavior.html "enum in java.awt") getBaselineResizeBehavior([JComponent](../../../../javax/swing/JComponent.html "class in javax.swing") c) Returns an enum indicating how the baseline of the component changes as the size changes. Overrides: `[getBaselineResizeBehavior](../../../../javax/swing/plaf/ComponentUI.html#getBaselineResizeBehavior-javax.swing.JComponent-)` in class `[ComponentUI](../../../../javax/swing/plaf/ComponentUI.html "class in javax.swing.plaf")` Parameters: `c` \- `JComponent` to return baseline resize behavior for Returns: an enum indicating how the baseline changes as the component size changes Throws: `[NullPointerException](../../../../java/lang/NullPointerException.html "class in java.lang")` \- if `c` is `null` Since: 1.6 See Also: [JComponent.getBaseline(int, int)](../../../../javax/swing/JComponent.html#getBaseline-int-int-) * #### createViewportChangeListener protected [ChangeListener](../../../../javax/swing/event/ChangeListener.html "interface in javax.swing.event") createViewportChangeListener() * #### createHSBChangeListener protected [ChangeListener](../../../../javax/swing/event/ChangeListener.html "interface in javax.swing.event") createHSBChangeListener() * #### createVSBChangeListener protected [ChangeListener](../../../../javax/swing/event/ChangeListener.html "interface in javax.swing.event") createVSBChangeListener() * #### createMouseWheelListener protected [MouseWheelListener](../../../../java/awt/event/MouseWheelListener.html "interface in java.awt.event") createMouseWheelListener() Creates an instance of MouseWheelListener, which is added to the JScrollPane by installUI(). The returned MouseWheelListener is used to handle mouse wheel-driven scrolling. Returns: MouseWheelListener which implements wheel-driven scrolling Since: 1.4 See Also: [installUI(javax.swing.JComponent)](../../../../javax/swing/plaf/basic/BasicScrollPaneUI.html#installUI-javax.swing.JComponent-), [BasicScrollPaneUI.MouseWheelHandler](../../../../javax/swing/plaf/basic/BasicScrollPaneUI.MouseWheelHandler.html "class in javax.swing.plaf.basic") * #### updateScrollBarDisplayPolicy protected void updateScrollBarDisplayPolicy([PropertyChangeEvent](../../../../java/beans/PropertyChangeEvent.html "class in java.beans") e) * #### updateViewport protected void updateViewport([PropertyChangeEvent](../../../../java/beans/PropertyChangeEvent.html "class in java.beans") e) * #### updateRowHeader protected void updateRowHeader([PropertyChangeEvent](../../../../java/beans/PropertyChangeEvent.html "class in java.beans") e) * #### updateColumnHeader protected void updateColumnHeader([PropertyChangeEvent](../../../../java/beans/PropertyChangeEvent.html "class in java.beans") e) * #### createPropertyChangeListener protected [PropertyChangeListener](../../../../java/beans/PropertyChangeListener.html "interface in java.beans") createPropertyChangeListener() Creates an instance of PropertyChangeListener that's added to the JScrollPane by installUI(). Subclasses can override this method to return a custom PropertyChangeListener, e.g. class MyScrollPaneUI extends BasicScrollPaneUI { protected PropertyChangeListener **createPropertyChangeListener**() { return new MyPropertyChangeListener(); } public class MyPropertyChangeListener extends PropertyChangeListener { public void propertyChange(PropertyChangeEvent e) { if (e.getPropertyName().equals("viewport")) { // do some extra work when the viewport changes } super.propertyChange(e); } } } See Also: [PropertyChangeListener](../../../../java/beans/PropertyChangeListener.html "interface in java.beans"), [installUI(javax.swing.JComponent)](../../../../javax/swing/plaf/basic/BasicScrollPaneUI.html#installUI-javax.swing.JComponent-)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.