Class ScrollPane
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
ScrollPane — AWT's scrolling container, not
JScrollPane. Holds exactly one child, gives it its
full size, and shows a movable window onto it. Peers over
SScrollPane (Vaadin Scroller).
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
sp.add(tallPanel); // a second add() evicts the first
sp.setScrollPosition(0, 200);
Point p = sp.getScrollPosition();
The scrollbars are not components
Unlike Swing'sJScrollBar, AWT's scrollbars are drawn by the peer
and never enter the component tree. What user code gets instead is a pair of
ScrollPaneAdjustable value models, one per axis, via
getVAdjustable() / getHAdjustable(). The range is derived, not
set: their setMinimum / setMaximum / setVisibleAmount
throw AWTError, verbatim as in AWT.
Scrolling is server→browser only
setScrollPosition(int, int) pushes to the browser and
getScrollPosition() reads back what was pushed — correct in the same
request, which is the common migrated idiom. But a user's wheel or drag is
invisible to the server: there is no scroll DOM listener, so
getScrollPosition() does not track a gesture and no
AdjustmentListener fires for one. Four migrated idioms break on this,
all silently — save/restore of a scroll offset, two panes synchronised
through an AdjustmentListener, "scroll to bottom only if already at
bottom", and hand-rolled paging near getMaximum(). Nothing
renders wrong: the browser owns overflow, and a Vaadin Grid or
VirtualList inside the pane lazy-loads over its own channel. Deliberate per
D_awt_scrollpane / SD_sscrollpane, which record why the read direction is not built.
Geometry answers are the JDK's own un-realized answers
getViewportSize() is always 100×100 and both scrollbar
dimensions are always 0 — which is literally what a never-laid-out JDK
ScrollPane reports (its ctor seeds width = height = 100, and
the scrollbar getters return 0 while peer == null). A rare case where
dummy geometry and JDK geometry agree exactly, so none of the three WARNs.
Leaf peer is locked down per R_leaf_peer_lockdown
Nothing injava.awt extends ScrollPane, and
javax.swing.plaf is out of scope (R_match_swing_errors sub-bucket (b)). Both public
ctors funnel into super(new SScrollPane(policy)), so every instance —
including a user-code subclass — peers over a Scroller and no ctor
offers a peer seam.
The policy constants are 0/1/2, numerically identical to
Adjustable's HORIZONTAL/VERTICAL/
NO_ORIENTATION. So new ScrollPane(Adjustable.VERTICAL)
compiles and silently means SCROLLBARS_ALWAYS — no throw,
wrong pane. The safe direction is
javax.swing.ScrollPaneConstants, whose values are 20–22 /
30–32 and therefore disjoint: one of those handed to this ctor
throws IllegalArgumentException, loudly.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intFields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, FILL_CHROME, FILL_DEFAULT, LEFT_ALIGNMENT, listenerList, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionChains tothis(SCROLLBARS_AS_NEEDED), as the JDK does.ScrollPane(int scrollbarDisplayPolicy) -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidAdds the single child, evicting any previous one.voidvoiddoLayout()Delegates tolayout()exactly as the JDK's does.intintintbooleanvoidlayout()Deprecated.Verbatim JDK format, including the empty-pane (0,0) fallback.voidUser-authoredGraphicspaint of components is permanently out of scope (R_match_swing_errors sub-bucket (b))protected voidThe hook is reachable —Component.processEventroutesMouseWheelEventhere — but nothing currently dispatches one, so in practice it does not run.voidremove(int index) Removes the child atindex, clearing the peer's content slot.final voidsetLayout(LayoutManager mgr) Refuses to install a layout manager, asjava.awt.ScrollPanedoes.voidsetScrollPosition(int x, int y) Scrolls to(x, y)within the child.voidvoidsetWheelScrollingEnabled(boolean handleWheel) Methods inherited from class Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, addSlotChild, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, fireHierarchyEvent, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, isValidateRoot, list, list, locate, minimumSize, paint, paintComponents, peerContentElement, preferredSize, print, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, removeSlotChild, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, update, validate, validateTreeMethods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, applyBackgroundToPeer, applyVisibleToPeer, awtListeners, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, defaultFillCssClass, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, fireComponentEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isThemeDefault, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, suppressMouseBridge, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, withPeer, withPeerOnLiveUI
-
Field Details
-
SCROLLBARS_AS_NEEDED
public static final int SCROLLBARS_AS_NEEDED- See Also:
-
SCROLLBARS_ALWAYS
public static final int SCROLLBARS_ALWAYS- See Also:
-
SCROLLBARS_NEVER
public static final int SCROLLBARS_NEVER- See Also:
-
-
Constructor Details
-
ScrollPane
public ScrollPane()Chains tothis(SCROLLBARS_AS_NEEDED), as the JDK does. -
ScrollPane
public ScrollPane(int scrollbarDisplayPolicy) - Parameters:
scrollbarDisplayPolicy-SCROLLBARS_AS_NEEDED,SCROLLBARS_ALWAYSorSCROLLBARS_NEVER- Throws:
IllegalArgumentException- on any other value, with AWT's message. Thrown out of the peer's constructor (D_awt_label's trick) so it fires insidesuper(...)and leaves no half-built ScrollPane
-
-
Method Details
-
addImpl
Adds the single child, evicting any previous one.The body order is AWT's and is observable: the existing child is removed before the index check, so
add(c2, null, 1)on a populated pane leaves the pane empty and then throws. A wart, but free to reproduce.Two departures from
java.awt.ScrollPane.addImpl.- No
addToPanelbranch. The JDK wraps a lightweight child in aPanelwith aBorderLayout, sogetComponent(0)there is the wrapper, not what you added. That fork exists to give a native scrolled-window a heavyweight child to host; our peer's shadow root is a bare<slot>that accepts any element, and SB-Emulators has no lightweight/heavyweight split to test in the first place. SogetComponent(0)here is the child — more permissive than the JDK, where the corresponding cast throwsClassCastException. See D_awt_scrollpane. addSlotChildrather thansuper.addImpl, becauseScrollerowns its content slot andContainer.addImplwouldinsertChildinto the peer element and fightsetContent(the D_shadow_children_tree_shape rationale, transferred verbatim).addSlotChildstill runs the add-to-self and ancestor-cycle checks and still firesCOMPONENT_ADDED+HIERARCHY_CHANGED.
Container.addImpl's ownIllegalArgumentException("illegal component position")bounds check is skipped: ScrollPane'sindex > 0check with its own message replaces it. - No
-
remove
public void remove(int index) Removes the child atindex, clearing the peer's content slot.Overridden where the JDK does not override it (there, the native peer handles removal). Necessary because
Container.remove(int)callsremoved.peer.getElement().removeFromParent(), which would rip the element out whileScroller.getContent()still pointed at it. This is also howaddImpl's ownremove(0)reaches the right code.- Overrides:
removein classContainer- Throws:
ArrayIndexOutOfBoundsException- if out of range, as in AWT
-
getScrollbarDisplayPolicy
public int getScrollbarDisplayPolicy()- Returns:
- the ctor-set policy; AWT provides no setter
-
getViewportSize
- Returns:
- always 100×100 — see the class javadoc. Computed directly
rather than through
getWidth()/getInsets(), which would WARN and answer 0; the JDK's ctor seedswidth = height = 100and its insets here are zero, so this constant is the faithful answer for a pane that was never laid out. Fresh instance — AWT lets callers mutate it
-
getHScrollbarHeight
public int getHScrollbarHeight()- Returns:
- always 0 — the JDK's own answer whenever
peer == nullor the policy isSCROLLBARS_NEVER. Our scrollbars are the browser's and report no dimensions
-
getVScrollbarWidth
public int getVScrollbarWidth()- Returns:
- always 0, for the same reason as
getHScrollbarHeight()
-
getVAdjustable
- Returns:
- the vertical axis's value model. Declared
Adjustablerather thanScrollPaneAdjustablebecause the JDK declares the wider type "to maintain backward compatibility"; narrowing it would diverge from the signature migrated code compiled against. Cast toScrollPaneAdjustableworks, as in AWT
-
getHAdjustable
- Returns:
- the horizontal axis's value model; see
getVAdjustable()
-
setScrollPosition
public void setScrollPosition(int x, int y) Scrolls to(x, y)within the child.Exactly
hAdjustable.setValue(x); vAdjustable.setValue(y), as in AWT, so it fires up to twoAdjustmentEvents. Unlike AWT the values are not clamped to the child's extent — seeScrollPaneAdjustablefor why, and note the browser clamps on arrival so the rendered result is still legal.- Throws:
NullPointerException- if the pane has no child. AWT chose NPE with this message rather than IllegalStateException
-
setScrollPosition
- Parameters:
p- the target position- Throws:
NullPointerException- ifpis null — thrown by thep.xdereference before the child check, so a null Point NPEs (without a message) even on an empty pane. Order matters and is AWT's
-
getScrollPosition
- Returns:
- the last position pushed, not necessarily where the user is — see the class javadoc. Fresh instance
- Throws:
NullPointerException- if the pane has no child, as in AWT
-
setLayout
Refuses to install a layout manager, asjava.awt.ScrollPanedoes.getLayout()therefore answers null forever. -
doLayout
public void doLayout()Delegates tolayout()exactly as the JDK's does. OurContainer.doLayout()dispatches to the LayoutManager and only falls through tolayout()when there is none — which happens to always be true here, sincesetLayout(LayoutManager)throws. Overriding makes thelayout()hook live by construction rather than by that coincidence (R_no_vaadin_in_api limb 2). -
layout
Deprecated.As of JDK 1.1, replaced bydoLayout(). Retained becausedoLayout()calls it and user code overrides it — AWT-era code hooks layout here. -
printComponents
User-authoredGraphicspaint of components is permanently out of scope (R_match_swing_errors sub-bucket (b))- Overrides:
printComponentsin classContainer- Parameters:
g- ignored
-
addNotify
-
processMouseWheelEvent
The hook is reachable —Component.processEventroutesMouseWheelEventhere — but nothing currently dispatches one, so in practice it does not run. That is an absent source rather than a dead hook, so R_no_vaadin_in_api limb 2 is satisfied. NoScrollPaneWheelScrollerarithmetic: that class is JDK-internal and the browser already wheel-scrolls the peer natively, which is what the flag asks for.e.consume()on the enabled path is the JDK's, kept so the call graph matches; per D_event_consume it marks the event and suppresses nothing, the browser having already scrolled- Overrides:
processMouseWheelEventin classComponent- Parameters:
e- the wheel event
-
setWheelScrollingEnabled
public void setWheelScrollingEnabled(boolean handleWheel) - Parameters:
handleWheel-falseis R_match_swing_errors sub-bucket (c) drop-and-WARN: CSS cannot disable the wheel while keeping scrollbars draggable (overflow: hiddenandScrollDirection.NONEboth kill scrolling outright). The value round-trips regardless;true, the default, is free because the browser wheel-scrolls the peer natively
-
isWheelScrollingEnabled
public boolean isWheelScrollingEnabled() -
paramString
Verbatim JDK format, including the empty-pane (0,0) fallback.- Overrides:
paramStringin classContainer
-
getAccessibleContext
- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classComponent- Returns:
- always null — accessibility contexts are permanently out of scope
(R_match_swing_errors sub-bucket (b)), as on
Panel/Button
-
doLayout().