Class JViewport

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class JViewport extends JComponent implements Accessible
Emulator for JViewport. Per D_viewport_scrollbar_shadows, a shadow JDK component: emulator-only, no surrogate counterpart. Vaadin's Scroller has no separate viewport object — Scroller.getContent() IS the viewport view, and the DOM rendering of "viewport bounds" is owned by the Scroller's web component. JViewport here exists to give migrated code that calls scrollPane.getViewport().getView() or scrollPane.getViewport().addChangeListener(...) a non-null object that round-trips its own state without NPE.

R_leaf_peer_lockdown-locked-down: no protected (Component peer) ctor exposed. Constructed only via the package-private JViewport(JScrollPane) ctor used by JScrollPane.getViewport().

Round-trip-only fields

Most viewport state (extentSize / viewPosition / viewSize) field-shadows but never drives the peer — Vaadin Scroller doesn't expose these as server-side concepts. Field round-trip is honest about JDK fidelity (user code reading back what it set sees its values); visible behaviour is "no scroll-position events fire."

Listeners stored but never fire

addChangeListener(ChangeListener) stores the listener in EventListenerList for round-trip; no Vaadin source fires ChangeEvents for scroll position without a custom DOM listener stack (R_match_swing_errors sub-bucket (a) — graduate when a migration target asks).
See Also:
  • Field Details

  • Constructor Details

    • JViewport

      public JViewport()
      Public no-arg ctor for migrated code that constructs a JViewport directly (rare but possible; some L&F-aware code does scrollPane.setViewport(new JViewport())). Owner is unbound until the JViewport is attached to a JScrollPane via setViewport, at which point bindOwner(JScrollPane) is called.
  • Method Details

    • getView

      public Component getView()
      The wrapped emulator component, resolved through the owning JScrollPane's getViewportView. Returns null if no owner is bound or no view is set.
    • setView

      public void setView(Component view)
      Replace the wrapped component — through the owning JScrollPane's JScrollPane.setViewportView(Component) when one is bound, and otherwise into this viewport's own child list, which is where the JDK keeps it either way (getView() is its getComponent(0)).

      An unbound viewport therefore still holds what it was given, scrolling being the effect R_decline_effect_only lets go and the view being state it does not.

    • addImpl

      protected void addImpl(Component child, Object constraints, int index)
      Every add(...) overload makes child the view, as the JDK's does — scrollPane.getViewport().add(view) is the common spelling of setViewportView(view). Constraints and index are ignored.
      Overrides:
      addImpl in class Container
    • getExtentSize

      public Dimension getExtentSize()
    • setExtentSize

      public void setExtentSize(Dimension newExtent)
    • getViewPosition

      public Point getViewPosition()
      The origin while no view is set, as in the JDK — there is nothing to ask.
    • setViewPosition

      public void setViewPosition(Point p)
      Store the scroll offset, or ignore it while the viewport holds no view.

      The no-view gate is the JDK's, and it is not a nicety. javax.swing.JViewport keeps no position field: it writes the offset onto the view's own location, negated, and getViewPosition() reads it back off the view — so with no view the write is dropped and the getter answers (0,0). SB-Emulators answered back whatever was set, on a viewport that held nothing (D_return_value_audit). The field stays because vaadinx.awt.Component drops setLocation (R_layouts_close_enough), so the view cannot hold the value for us; with a view present the observable round trip is the same either way. A null point NPEs here exactly where the JDK's p.x read does.

    • getViewSize

      public Dimension getViewSize()
      As getViewPosition(), the origin while no view is set.
    • setViewSize

      public void setViewSize(Dimension newSize)
      Same no-view gate and same reason as setViewPosition(Point).
    • getViewRect

      public Rectangle getViewRect()
    • getScrollMode

      public int getScrollMode()
    • setScrollMode

      public void setScrollMode(int mode)
      Stores the mode with no peer effect — Vaadin owns scroll rendering.

      Deliberately accepts a mode outside the three JDK constants, because the JDK does: setScrollMode(99) then getScrollMode() answers 99 on JDK 25. Rejecting it would be the kind of unrequested improvement R_no_silent_improvements forbids — a migrated app that got away with a junk mode on the desktop must get away with it here.

    • addChangeListener

      public void addChangeListener(ChangeListener l)
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
    • getChangeListeners

      public ChangeListener[] getChangeListeners()
    • scrollRectToVisible

      public void scrollRectToVisible(Rectangle contentRect)
      Overrides:
      scrollRectToVisible in class JComponent
    • getInsets

      public Insets getInsets()
      Overrides:
      getInsets in class JComponent
    • getInsets

      public Insets getInsets(Insets insets)
      Overrides:
      getInsets in class JComponent
    • getUIClassID

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

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

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

      public void setUI(ViewportUI ui)
    • getAccessibleContext

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