Class JScrollPane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, ScrollPaneConstants

public class JScrollPane extends JComponent implements ScrollPaneConstants, Accessible
Emulator for JScrollPane. Per D_jscrollpane, a thin delegating shell over the SJScrollPane surrogate (extends Vaadin Scroller). The scrollbar-policy ints field-shadow JDK-faithfully (R_swing_is_truth store-then-drive); the setScrollDirection push to the surrogate is skipped when the current viewport content is auto-scrolling (per SD_sjscrollpane's setContent override on the surrogate side), so user code reading back its policy ints sees what it set even when wrapping a Grid / TextArea.

R_leaf_peer_lockdown-locked-down: no protected (Component peer) ctor — every public ctor funnels through a private (SJScrollPane) ctor that hard-codes the surrogate. JScrollPane is a leaf in the public javax.swing.* hierarchy, so user-code subclasses extend the public form and inherit the locked-in peer.

JViewport and JScrollBar are emulator-only shadow JDK components (per D_viewport_scrollbar_shadows — Vaadin has no separate viewport object; Vaadin Scroller's web component owns scrollbar rendering internally). The shadow ports field-shadow their JDK state for round-trip but never fire listeners (no Vaadin source for scroll-position events without a custom DOM stack — R_match_swing_errors sub-bucket (a) until a migration target asks).

See Also:
  • Field Details

    • verticalScrollBarPolicy

      protected int verticalScrollBarPolicy
    • horizontalScrollBarPolicy

      protected int horizontalScrollBarPolicy
    • viewport

      protected JViewport viewport
    • horizontalScrollBar

      protected JScrollBar horizontalScrollBar
    • verticalScrollBar

      protected JScrollBar verticalScrollBar
    • columnHeader

      protected JViewport columnHeader
    • rowHeader

      protected JViewport rowHeader
    • lowerLeft

      protected Component lowerLeft
    • lowerRight

      protected Component lowerRight
    • upperLeft

      protected Component upperLeft
    • upperRight

      protected Component upperRight
  • Constructor Details

    • JScrollPane

      public JScrollPane()
    • JScrollPane

      public JScrollPane(Component view)
    • JScrollPane

      public JScrollPane(int vsbPolicy, int hsbPolicy)
    • JScrollPane

      public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
  • Method Details

    • setViewportView

      public void setViewportView(Component view)
      Set the wrapped component. Field-shadows the emulator-side reference, delegates to SJScrollPane.setContent(com.vaadin.flow.component.Component) (which applies the auto-scroll guard per SD_sjscrollpane), then re-pushes the scrollbar policy via pushPolicyToSurrogate() — the push is a no-op when content is auto-scrolling.
    • getViewportView

      public Component getViewportView()
      The wrapped emulator component, or null if none was set.
    • getViewport

      public JViewport getViewport()
      Returns the JViewport that wraps the viewport view. Eagerly constructed in the ctor (added to Container.components so the JDK tree shape round-trips). Per D_viewport_scrollbar_shadows, the JViewport is an emulator-only shadow JDK component — its getView / setView round-trip the wrapped component, but viewport-position / extent-size APIs are round-trip-only (no Vaadin counterpart).
    • setViewport

      public void setViewport(JViewport vp)
      Replace the JViewport. JDK contract: the new viewport's view becomes the JScrollPane's viewport view. The old viewport is detached from Container.components and the new one inserted at the same index (viewport always lives at index 0 — JDK ordering).
    • getHorizontalScrollBar

      public JScrollBar getHorizontalScrollBar()
    • getVerticalScrollBar

      public JScrollBar getVerticalScrollBar()
    • setHorizontalScrollBar

      public void setHorizontalScrollBar(JScrollBar sb)
      Replace the horizontal scrollbar. JDK accepts user-supplied JScrollBar instances (rare; common in subclassed L&F-aware code). The old scrollbar is detached from Container.components and the new one inserted at the same JDK index (2 — after viewport and verticalScrollBar). No DOM impact: Vaadin Scroller renders its own scrollbar; the shadow's inert Div peer stays out of the peer DOM.
    • setVerticalScrollBar

      public void setVerticalScrollBar(JScrollBar sb)
    • getVerticalScrollBarPolicy

      public int getVerticalScrollBarPolicy()
    • setVerticalScrollBarPolicy

      public void setVerticalScrollBarPolicy(int policy)
    • getHorizontalScrollBarPolicy

      public int getHorizontalScrollBarPolicy()
    • setHorizontalScrollBarPolicy

      public void setHorizontalScrollBarPolicy(int policy)
    • setViewportBorder

      public void setViewportBorder(Border viewportBorder)
    • getViewportBorder

      public Border getViewportBorder()
    • setColumnHeaderView

      public void setColumnHeaderView(Component view)
    • setRowHeaderView

      public void setRowHeaderView(Component view)
    • setColumnHeader

      public void setColumnHeader(JViewport columnHeader)
      Stores the header viewport and fires "columnHeader"; nothing is rendered. A Vaadin Scroller has one content slot and no header/corner grid, so the JDK's add(columnHeader, COLUMN_HEADER) has no target — the declined effect. State and notification are owed regardless (R_decline_effect_only, D_owed_events).
    • getColumnHeader

      public JViewport getColumnHeader()
    • setRowHeader

      public void setRowHeader(JViewport rowHeader)
      Stores and fires; nothing is rendered — see setColumnHeader(JViewport).
    • getRowHeader

      public JViewport getRowHeader()
    • setCorner

      public void setCorner(String key, Component corner)
      Stores the corner and fires the key-named bound property; nothing is rendered — see setColumnHeader(JViewport). Invalid keys throw IllegalArgumentException as in the JDK (R_match_swing_errors).
    • getCorner

      public Component getCorner(String key)
    • setWheelScrollingEnabled

      public void setWheelScrollingEnabled(boolean handleWheel)
    • isWheelScrollingEnabled

      public boolean isWheelScrollingEnabled()
    • setLayout

      public void setLayout(LayoutManager mgr)
      Accepts only null, throwing the JDK's own ClassCastException and message for anything else — javax.swing.JScrollPane.setLayout takes a ScrollPaneLayout or null and rejects the rest, so tolerating a BorderLayout here would let code run that fails on the desktop (R_match_swing_errors).

      The JDK's accept-branch has nothing to accept, and costs nothing: SB-Emulators ports no ScrollPaneLayout (its viewport / header / corner orchestration is R_vaadin_first drop-and-WARN per D_jscrollpane, the peer being one content slot), and javax.swing.ScrollPaneLayout is not a vaadinx.awt.LayoutManager, so a migrator's surviving call would not compile either way.

      Overrides:
      setLayout in class Container
      Parameters:
      mgr - must be null
      Throws:
      ClassCastException - for any non-null manager
    • validateTree

      protected void validateTree()
      setViewportView attaches the view through Scroller.setContent (one-content-slot per SD_sjscrollpane), bypassing Container.addImpl — the view never enters this JScrollPane's components list. The inherited Container.validateTree() walks components only, so without this override an inner panel created with new JPanel() then setLayout(new BoxLayout(...)) keeps the FlowLayout CSS the SJPanel ctor wrote at construction time — its BoxLayout never gets a layoutContainer pass. Recursing into the viewportView closes that gap.
      Overrides:
      validateTree in class Container
    • getUIClassID

      public String getUIClassID()
      Overrides:
      getUIClassID in class JComponent
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JComponent
    • getUI

      public ScrollPaneUI getUI()
      Overrides:
      getUI in class JComponent
    • setUI

      public void setUI(ScrollPaneUI ui)
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()
      Specified by:
      getAccessibleContext in interface Accessible
      Overrides:
      getAccessibleContext in class Component