public class ScrollContainer extends Container implements Scrollable, UpdateListener
Caution: you must not use RIGHT, BOTTOM, CENTER and FILL when setting the control bounds, unless you disable the corresponding ScrollBar! The only exception to this is to use FILL on the control's height, which is allowed.
Here is an example showing how it can be used:
public class MyProgram extends MainWindow { ScrollContainer sc; public void initUI() { ScrollContainer sc; add(sc = new ScrollContainer()); sc.setBorderStyle(BORDER_SIMPLE); sc.setRect(LEFT+10,TOP+10,FILL-20,FILL-20); int xx = new Label("Name99").getPreferredWidth()+2; // edit's alignment for (int i =0; i < 100; i++) { sc.add(new Label("Name"+i),LEFT,AFTER); sc.add(new Edit("@@@@@@@@@@@@@@@@@@@@"),xx,SAME); if (i % 3 == 0) sc.add(new Button("Go"), AFTER+2,SAME,PREFERRED,SAME); } } }
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
boolean |
autoScroll
Automatically scrolls the container when an item is clicked.
|
protected ClippedContainer |
bag |
protected Container |
bag0 |
protected Flick |
disabledFlick |
protected Flick |
flick
The Flick object listens and performs flick animations on PenUp events when appropriate.
|
static java.util.HashSet<java.lang.Class<?>> |
hsIgnoreAutoScroll
Defines a list of classes that will make autoScroll be ignored.
|
protected int |
lastH |
protected int |
lastV |
ScrollBar |
sbH
Returns the scrollbar for this ScrollContainer.
|
ScrollBar |
sbV
Returns the scrollbar for this ScrollContainer.
|
boolean |
shrink2size
Set to true, to make the surrounding container shrink to its size.
|
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastScreenWidth, lastW, lastX, lastY, numChildren, started, tabOrder, tail, TRANSITION_TIME
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
Constructor and Description |
---|
ScrollContainer()
Standard constructor for a new ScrollContainer, with both scrollbars enabled.
|
ScrollContainer(boolean allowScrollBars)
Constructor used to specify when both scrollbars are enabled or not.
|
ScrollContainer(boolean allowHScrollBar,
boolean allowVScrollBar)
Constructor used to specify when each scrollbar is enabled or not.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Control control)
Adds a child control to the bag container.
|
void |
addScrollEventHandler(ScrollEventHandler scrollEventHandler)
Add an instance of ScrollEventHandler
|
protected void |
bagSetRect(int x,
int y,
int w,
int h,
boolean screenChanged) |
boolean |
canScrollContent(int direction,
java.lang.Object target)
Checks if there is room to flick this container in the given direction.
|
protected boolean |
canShowScrollBars(boolean vertical) |
void |
disableFlick()
Disables the 'flick' behaviour from this scroll container.
|
void |
enableFlick()
Reenables the 'flick' behaviour of this container.
|
void |
flickEnded(boolean atPenDown)
Called when the flick animation is ended.
|
boolean |
flickStarted()
Called when the flick animation is started.
|
Control[] |
getBagChildren()
Returns the children of the bag.
|
protected int |
getBagInitialHeight()
Overwrite this method to define a custom height for the scrolling area
|
protected int |
getBagInitialWidth()
Overwrite this method to define a custom width for the scrolling area
|
Rect |
getClientRect()
Returns the client rect from the area that scrolls
|
Flick |
getFlick()
Returns the current flick object.
|
int |
getPreferredHeight()
Returns the preferred height AFTER the resize method was called.
|
int |
getPreferredWidth()
Returns the preferred width AFTER the resize method was called.
|
Rect |
getRealClientRect()
Returns the client rect from the ScrollContainer control
|
int |
getScrollDistance()
Override this method to return the correct scroll distance.
|
int |
getScrollPosition(int direction)
Returns the current position given the direction.
|
Control |
moveFocusToNextControl(Control control,
boolean forward)
Moves the focus to the next control, which can be an Edit, a MultiEdit, or another control type.
|
protected void |
onBoundsChanged(boolean screenChanged)
Called after a setRect.
|
protected void |
onColorsChanged(boolean colorsChanged)
Called after a setEnabled, setForeColor and setBackColor and when a control has
been added to a Container.
|
void |
onEvent(Event event)
Called to process key, pen, control and other posted events.
|
void |
onFontChanged()
Called after a setFont
|
void |
onPaint(Graphics g)
Draws the border (if any).
|
void |
remove(Control control)
Removes a child control from the bag container.
|
void |
removeAll()
Removes all controls from the ScrollContainer.
|
void |
removeScrollEventHandler(ScrollEventHandler scrollEventHandler)
Remove an specified instance of ScrollEventHandler
|
void |
reposition()
Reposition this control, calling again setRect with the original parameters.
|
void |
resize()
This method resizes the control to the needed bounds, based on added childs.
|
void |
resize(int maxX,
int maxY)
This method resizes the control to the needed bounds, based on the given maximum width and heights.
|
boolean |
scrollContent(int dx,
int dy,
boolean fromFlick)
Performs a relative move.
|
void |
scrollPage(boolean left)
Scrolls a page to left or right.
|
void |
scrollToControl(Control c)
Scrolls to the given control.
|
void |
scrollToOrigin()
Scroll the container to origin position 0,0
|
void |
scrollToPage(int p)
Scrolls to the given page, which is the flick's scrollDistance (if set), or the control's height.
|
void |
setBorderStyle(byte border)
Sets the border for this container.
|
void |
setHandlersVisibility(boolean visible)
Changes the visibility of the temporary scrollbar handlers.
|
void |
setHandlersVisibility(boolean horizontalHandlerVisiblle,
boolean verticalHandlerVisible)
Changes the visibility of the temporary scrollbar handlers individually.
|
protected void |
setHValue(int val)
Sets the horizontal's ScrollBar value to the given one.
|
protected void |
setScrollBars(boolean allowHScrollBar,
boolean allowVScrollBar) |
protected void |
setVValue(int val)
Sets the vertical's ScrollBar value to the given one.
|
void |
updateListenerTriggered(int elapsedMilliseconds)
Called regularly by the system.
|
boolean |
wasScrolled()
Returns true if the control was scrolled since last pen down
|
add, add, add, add, broadcastEvent, clear, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resizeHeight, resizeWidth, setBorderRadius, setEnabled, setFocusTraversable, setHighlighting, setInsets, setPressColor, setPressed, swapToTopmostWindow
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
public ScrollBar sbH
sbV.transparentBackground=true
(or for sbH), you will expand the client area to over the ScrollPosition's area.public ScrollBar sbV
sbV.transparentBackground=true
(or for sbH), you will expand the client area to over the ScrollPosition's area.protected Flick flick
protected Flick disabledFlick
protected ClippedContainer bag
protected Container bag0
protected int lastV
protected int lastH
public boolean shrink2size
public boolean autoScroll
hsIgnoreAutoScroll
public static java.util.HashSet<java.lang.Class<?>> hsIgnoreAutoScroll
ScrollContainer.hsIgnoreAutoScroll.add(totalcross.ui.SpinList.class); ...This is useful if such class usually requires more than one press to have a value defined.
autoScroll
public ScrollContainer()
public ScrollContainer(boolean allowScrollBars)
public ScrollContainer(boolean allowHScrollBar, boolean allowVScrollBar)
public Rect getClientRect()
getClientRect
in class Container
Container.getClientRect(Rect)
public Rect getRealClientRect()
protected void setScrollBars(boolean allowHScrollBar, boolean allowVScrollBar)
protected int getBagInitialHeight()
protected int getBagInitialWidth()
public boolean flickStarted()
Scrollable
flickStarted
in interface Scrollable
public void flickEnded(boolean atPenDown)
Scrollable
flickEnded
in interface Scrollable
atPenDown
- Flag indicating if the animation ended due to a pendown event.public boolean canScrollContent(int direction, java.lang.Object target)
Scrollable
canScrollContent
in interface Scrollable
direction
- The direction we want to flick given by one of the following constants:target
- The target of the series of PEN events that triggered this flick attempt.public boolean scrollContent(int dx, int dy, boolean fromFlick)
Scrollable
scrollContent
in interface Scrollable
dx
- The relative amount of pixels to move in the X axis.dy
- The relative amount of pixels to move in the Y axis.public void updateListenerTriggered(int elapsedMilliseconds)
UpdateListener
updateListenerTriggered
in interface UpdateListener
elapsedMilliseconds
- number of milliseconds since the last UpdateListenerTriggered callpublic int getScrollPosition(int direction)
Scrollable
getScrollPosition
in interface Scrollable
public void add(Control control)
public void remove(Control control)
protected void onBoundsChanged(boolean screenChanged)
Control
onBoundsChanged
in class Control
screenChanged
- If the bounds were changed due to a screen change (rotation, collapse)protected void onColorsChanged(boolean colorsChanged)
Control
onColorsChanged
in class Container
protected void bagSetRect(int x, int y, int w, int h, boolean screenChanged)
public void resize()
resize
in class Container
Container.resizeWidth()
,
Container.resizeHeight()
public void resize(int maxX, int maxY)
protected boolean canShowScrollBars(boolean vertical)
public int getScrollDistance()
public void reposition()
Control
reposition
in class Control
public int getPreferredWidth()
getPreferredWidth
in class Control
public int getPreferredHeight()
getPreferredHeight
in class Control
public void onPaint(Graphics g)
Container
super.onPaint(g);
, or the border will not be drawn.public void onEvent(Event event)
Control
public void scrollToPage(int p)
public void scrollPage(boolean left)
public void scrollToControl(Control c)
public void scrollToOrigin()
protected void setVValue(int val)
protected void setHValue(int val)
public void setBorderStyle(byte border)
Container
setBorderStyle
in class Container
Container.BORDER_NONE
,
Container.BORDER_LOWERED
,
Container.BORDER_RAISED
,
Container.BORDER_SIMPLE
,
Container.BORDER_TOP
,
Container.BORDER_ROUNDED
public Flick getFlick()
Scrollable
getFlick
in interface Scrollable
public boolean wasScrolled()
Scrollable
wasScrolled
in interface Scrollable
public void removeAll()
public Control[] getBagChildren()
public void onFontChanged()
Control
onFontChanged
in class Control
public Control moveFocusToNextControl(Control control, boolean forward)
Container
moveFocusToNextControl
in class Container
public void disableFlick()
enableFlick
public void enableFlick()
public void setHandlersVisibility(boolean visible)
public void setHandlersVisibility(boolean horizontalHandlerVisiblle, boolean verticalHandlerVisible)
public void addScrollEventHandler(ScrollEventHandler scrollEventHandler)
scrollEventHandler
- public void removeScrollEventHandler(ScrollEventHandler scrollEventHandler)
scrollEventHandler
-