Class Sheet
- All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>
A light-weight dialog that slides up from the bottom of the screen on mobile devices.
Sheets include a "title" bar, with a back/close button, a title label, and a "commands container" (#getCommandsContainer())
which allows you to insert your own custom components (usually buttons) in the upper right.
Custom content should be placed inside the content pane which can be retrieved via #getContentPane()
Usage
The general usage is to create new Sheet instance (or subclass), then call #show()
to make it appear over the current form. If a different sheet that is currently being displayed, then
calling #show() will replace it.
Inter-Sheet Navigation
The java.lang.String) constructor can take another
Sheet object as a parameter, which will act as a "parent" sheet (#getParentSheet(). If the parent
sheet is not null, then this sheet will have a "Back" button instead of a "Close" button. THe
"Back" button will navigate back to the parent sheet.
When navigating between sheets, the sheet will be resized with a smooth slide animation to the preferred height of the destination sheet.
Example
`public void start() {
if(current != null){
current.show();
return;`
Form hi = new Form("Hi World", new BorderLayout());
Button b = new Button("Open Sheet");
b.addActionListener(e->{
new MySheet(null).show();
});
hi.add(BorderLayout.NORTH, b);
hi.show();
}
private class MySheet extends Sheet {
MySheet(Sheet parent) {
super(parent, "My Sheet");
Container cnt = getContentPane();
cnt.setLayout(BoxLayout.y());
Button gotoSheet2 = new Button("Goto Sheet 2");
gotoSheet2.addActionListener(e->{
new MySheet2(this).show(300);
});
cnt.add(gotoSheet2);
for (String t : new String[]{"Red", "Green", "Blue", "Orange"}) {
cnt.add(new Label(t));
}
}
}
private class MySheet2 extends Sheet {
MySheet2(Sheet parent) {
super(parent, "Sheet 2");
Container cnt = getContentPane();
cnt.setLayout(BoxLayout.y());
cnt.setScrollableY(true);
for (int i=0; iVideo Sample
[Screen cast of the SheetSample demo](https://youtu.be/3okEj_JW3-k)
View source for this sample [here](https://github.com/codenameone/CodenameOne/tree/master/Samples/samples/SheetSample).
This sample can be run directly in the [SampleRunner](https://github.com/codenameone/CodenameOne/tree/master/Samples/).
@author shannah
#### Since
7.0
-
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds listener to be notified when user goes back to the parent.voidAdds listener notified when the sheet is closed.voidback()Goes back to the parent sheet with a default (300ms) slide animation.voidback(int duration) Goes back to the parent sheet with a slide animation of given duration.protected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.static SheetFinds Sheet containing this component if it is currently part of a Sheet.Gets the container that is rendered on the top right bar of the sheet.Gets the content pane of the sheet.static SheetGets the current sheet on the current form or null if no sheet is currently being displayed.Gets the parent sheet or null if there is none.Gets the position where the Sheet is to be displayed.voidHides the back button.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component statebooleanChecks whether the user is allowed to close this sheet.booleanisAncestorSheetOf(Sheet sheet) Checks if the current sheet is an ancestor sheet of the given sheet.static booleanisSheetVisibleAt(int x, int y) voidRemoves a back listener.voidRemoves a close listener.voidsetAllowClose(boolean allowClose) Sets whether the user is able to close this sheet.voidsetHeight(int height) Sets the Component height, this method is exposed for the purpose of external layout managers and should not be invoked directly.voidsetPosition(String position) Sets the position where the Sheet is to be displayed.voidsetPosition(String phonePosition, String tabletPosition) Sets the position where the Sheet is to be displayed.voidsetWidth(int width) Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.voidsetX(int x) Sets the Component x location relative to the parent container, this method is exposed for the purpose of external layout managers and should not be invoked directly.voidsetY(int y) Sets the Component y location relative to the parent container, this method is exposed for the purpose of external layout managers and should not be invoked directly.voidshow()Shows the sheet with the default (300ms) transition duration.voidshow(int duration) Shows the sheet over the current form using a slide-up transition with given duration in milliseconds.voidShows the back button.Methods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVisible, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
Sheet
Creates a new sheet with the specified parent and title.
Parameters
-
parent: Optional parent sheet. If non-null, then this sheet will have a "back" button instead of a "close" button. The "back" button will return to the parent sheet. -
title: The title to display in the title bar of the sheet.
-
-
Sheet
Creates a new sheet with the specified parent and title.
Parameters
-
parent: Optional parent sheet. If non-null, then this sheet will have a "back" button instead of a "close" button. The "back" button will return to the parent sheet. -
title: The title to display in the title bar of the sheet. -
uiid: @param uiid Optional UIID for the sheet. If non-null, then the Sheet's uiid will be uiid, the title label's UIID will be uiid + "Title", the title bar's UIID will be uiid + "TitleBar", and the back/close button's UIID will be uiid + "BackButton".
-
-
-
Method Details
-
isSheetVisibleAt
public static boolean isSheetVisibleAt(int x, int y) -
getCurrentSheet
Gets the current sheet on the current form or null if no sheet is currently being displayed.
Returns
The current sheet or null.
Since
7.0
-
findContainingSheet
-
isAllowClose
public boolean isAllowClose()Checks whether the user is allowed to close this sheet.
Returns
True if user can close the sheet.
-
setAllowClose
public void setAllowClose(boolean allowClose) Sets whether the user is able to close this sheet. Default is true. If you set this value to false, then there will be no close button, and pressing outside of the sheet will have no effect.
Child sheets will assume the settings of the parent. The back button will still work, but the top level sheet will not include a close button.
Parameters
allowClose: True to allow user to close the sheet. False to prevent it.
Since
7.0
-
getContentPane
Gets the content pane of the sheet. All sheet content should be added to the content pane and not directly to the sheet.
Returns
The content pane.
-
hideBackButton
public void hideBackButton()Hides the back button. -
showBackButton
public void showBackButton()Shows the back button. -
getCommandsContainer
Gets the container that is rendered on the top right bar of the sheet. Use this to add buttons and other content you wish to appear in the title bar. Best not to overload this with too many things. -
show
public void show()Shows the sheet with the default (300ms) transition duration.
See also
- #show(int)
-
show
public void show(int duration) Shows the sheet over the current form using a slide-up transition with given duration in milliseconds.
If another sheet is currently being shown, then this will replace that sheet, and use an appropriate slide animation to adjust the size.
Parameters
duration: The duration of the slide transition in milliseconds.
See also
- #show()
-
getPosition
Gets the position where the Sheet is to be displayed. One of
BorderLayout#CENTER,BorderLayout#NORTH,BorderLayout#SOUTH,BorderLayout#WEST.Default is {@link BorderLayout#SOUTH.See also
-
#setPosition(java.lang.String)
-
#setPosition(java.lang.String, java.lang.String)
-
-
setPosition
Sets the position where the Sheet is to be displayed. One of
BorderLayout#CENTER,BorderLayout#NORTH,BorderLayout#SOUTH,BorderLayout#WEST.Default is {@link BorderLayout#SOUTH.Parameters
position: @param position One ofBorderLayout#CENTER,BorderLayout#NORTH,BorderLayout#SOUTH,BorderLayout#WEST.
invalid @link
{@link BorderLayout#EAST.Since
7.0
See also
-
#setPosition(java.lang.String)
-
#setPosition(java.lang.String, java.lang.String)
-
setPosition
Sets the position where the Sheet is to be displayed. One of
BorderLayout#CENTER,BorderLayout#NORTH,BorderLayout#SOUTH,BorderLayout#WEST.Default is {@link BorderLayout#SOUTH.Parameters
phonePosition: @param phonePosition Position to use on a phone (i.e. non-tablet). One ofBorderLayout#CENTER,BorderLayout#NORTH,BorderLayout#SOUTH,BorderLayout#WEST.@param tabletPosition Position to use on a tablet and desktop. One of {@link BorderLayout#CENTER,BorderLayout#NORTH,BorderLayout#SOUTH,BorderLayout#WEST.
invalid @link
{@link BorderLayout#EAST.Since
7.0
See also
-
#setPosition(java.lang.String)
-
#setPosition(java.lang.String, java.lang.String)
-
back
public void back()Goes back to the parent sheet with a default (300ms) slide animation. If there is no parent sheet, then this will close the sheet.
See also
- #back(int)
-
back
public void back(int duration) Goes back to the parent sheet with a slide animation of given duration. If there is no parent sheet, then this will close the sheet.
Parameters
duration: Duration of the slide transition in milliseconds.
-
setX
public void setX(int x) Description copied from class:ComponentSets the Component x location relative to the parent container, this method is exposed for the purpose of external layout managers and should not be invoked directly.
Parameters
x: the current x coordinate of the components origin
-
setY
public void setY(int y) Description copied from class:ComponentSets the Component y location relative to the parent container, this method is exposed for the purpose of external layout managers and should not be invoked directly.
Parameters
y: the current y coordinate of the components origin
-
setWidth
public void setWidth(int width) Description copied from class:ComponentSets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.
If a user wishes to affect the component size, setPreferredSize should be used.
Parameters
width: the width of the component
See also
- #setPreferredSize
-
setHeight
public void setHeight(int height) Description copied from class:ComponentSets the Component height, this method is exposed for the purpose of external layout managers and should not be invoked directly.
If a user wishes to affect the component size, setPreferredSize should be used.
Parameters
height: the height of the component
See also
- #setPreferredSize
-
getParentSheet
Gets the parent sheet or null if there is none.
Returns
The parent sheet or null.
-
initComponent
protected void initComponent()Description copied from class:ComponentAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classComponent
-
deinitialize
protected void deinitialize()Description copied from class:ComponentInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.- Overrides:
deinitializein classComponent
-
isAncestorSheetOf
Checks if the current sheet is an ancestor sheet of the given sheet.
Parameters
sheet: The sheet to check
Returns
True if the current sheet is an ancestor of sheet.
Since
7.0
-
addCloseListener
Adds listener notified when the sheet is closed. This event is only fired when the sheet is closed without the possibility of being reopened. E.g. if a child sheet is opened (causing this sheet to be hidden), the close event won't be fired until either that child sheet is hidden (without going back), or the sheet itself is hidden, or goes back.
Parameters
l
Since
7.0
-
removeCloseListener
Removes a close listener.
Parameters
l: The close listener
-
addBackListener
Adds listener to be notified when user goes back to the parent. This is not fired if the sheet is simply closed. Only if the "back" button is pressed,
Parameters
l: Listener
Since
7.0
-
removeBackListener
Removes a back listener.
Parameters
l: The close listener
-