public class Sheet extends 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()
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.
The Sheet(com.codename1.ui.Sheet, 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; i<2; i++) {
for (String t : new String[]{"Red", "Green", "Blue", "Orange"}) {
cnt.add(new Label(t));
}
}
}
}
Screen cast of the SheetSample demo
View source for this sample here. This sample can be run directly in the SampleRunner.
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 and Description |
---|
Sheet(Sheet parent,
String title)
Creates a new sheet with the specified parent and title.
|
Sheet(Sheet parent,
String title,
String uiid)
Creates a new sheet with the specified parent and title.
|
Modifier and Type | Method and Description |
---|---|
void |
addBackListener(ActionListener l)
Adds listener to be notified when user goes back to the parent.
|
void |
addCloseListener(ActionListener l)
Adds listener notified when the sheet is closed.
|
void |
back()
Goes back to the parent sheet with a default (300ms) slide animation.
|
void |
back(int duration)
Goes back to the parent sheet with a slide animation of given duration.
|
protected void |
deinitialize()
Invoked to indicate that the component initialization is being reversed
since the component was detached from the container hierarchy.
|
static Sheet |
findContainingSheet(Component cmp)
Finds Sheet containing this component if it is currently part of a Sheet.
|
Container |
getCommandsContainer()
Gets the container that is rendered on the top right bar of the sheet.
|
Container |
getContentPane()
Gets the content pane of the sheet.
|
static Sheet |
getCurrentSheet()
Gets the current sheet on the current form or null if no sheet is currently being displayed.
|
Sheet |
getParentSheet()
Gets the parent sheet or null if there is none.
|
String |
getPosition()
Gets the position where the Sheet is to be displayed.
|
void |
hideBackButton()
Hides the back button.
|
protected void |
initComponent()
Allows subclasses to bind functionality that relies on fully initialized and
"ready for action" component state
|
boolean |
isAllowClose()
Checks whether the user is allowed to close this sheet.
|
boolean |
isAncestorSheetOf(Sheet sheet)
Checks if the current sheet is an ancestor sheet of the given sheet.
|
void |
removeBackListener(ActionListener l)
Removes a back listener.
|
void |
removeCloseListener(ActionListener l)
Removes a close listener.
|
void |
setAllowClose(boolean allowClose)
Sets whether the user is able to close this sheet.
|
void |
setPosition(String position)
Sets the position where the Sheet is to be displayed.
|
void |
setPosition(String phonePosition,
String tabletPosition)
Sets the position where the Sheet is to be displayed.
|
void |
show()
Shows the sheet with the default (300ms) transition duration.
|
void |
show(int duration)
Shows the sheet over the current form using a slide-up transition with given duration in milliseconds.
|
void |
showBackButton()
Shows the back button.
|
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, paintBackground, paintBorderBackground, 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, updateTabIndices
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, 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, paintBackgrounds, paintBorder, 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, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, 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, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
public Sheet(Sheet parent, String title)
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.public Sheet(Sheet parent, String title, String uiid)
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
- 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".public void setAllowClose(boolean allowClose)
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.
allowClose
- True to allow user to close the sheet. False to prevent it.public boolean isAllowClose()
public Container getContentPane()
public void hideBackButton()
public void showBackButton()
public Container getCommandsContainer()
public void show()
show(int)
public static Sheet getCurrentSheet()
public void show(int duration)
If another sheet is currently being shown, then this will replace that sheet, and use an appropriate slide animation to adjust the size.
duration
- The duration of the slide transition in milliseconds.show()
public String getPosition()
BorderLayout.CENTER
, BorderLayout.NORTH
, BorderLayout.SOUTH
,
BorderLayout.WEST
. BorderLayout#EAST. Default is {@link BorderLayout#SOUTH}.public void setPosition(String position)
BorderLayout.CENTER
, BorderLayout.NORTH
, BorderLayout.SOUTH
,
BorderLayout.WEST
. BorderLayout#EAST. Default is {@link BorderLayout#SOUTH}.position
- One of BorderLayout.CENTER
, BorderLayout.NORTH
, BorderLayout.SOUTH
,
BorderLayout.WEST
. {@link BorderLayout#EAST.setPosition(java.lang.String)
,
setPosition(java.lang.String, java.lang.String)
public void setPosition(String phonePosition, String tabletPosition)
BorderLayout.CENTER
, BorderLayout.NORTH
, BorderLayout.SOUTH
,
BorderLayout.WEST
. BorderLayout#EAST. Default is {@link BorderLayout#SOUTH}.phonePosition
- Position to use on a phone (i.e. non-tablet). One of BorderLayout.CENTER
, BorderLayout.NORTH
, BorderLayout.SOUTH
,
BorderLayout.WEST
. {@link BorderLayout#EAST.tabletPosition
- Position to use on a tablet and desktop. One of BorderLayout.CENTER
, BorderLayout.NORTH
, BorderLayout.SOUTH
,
BorderLayout.WEST
. {@link BorderLayout#EAST.setPosition(java.lang.String)
,
setPosition(java.lang.String, java.lang.String)
public void back()
back(int)
public void back(int duration)
duration
- Duration of the slide transition in milliseconds.public Sheet getParentSheet()
protected void initComponent()
Component
initComponent
in class Component
protected void deinitialize()
Component
deinitialize
in class Component
public static Sheet findContainingSheet(Component cmp)
cmp
- The component to check.public boolean isAncestorSheetOf(Sheet sheet)
sheet
- The sheet to checkpublic void addCloseListener(ActionListener l)
l
- public void removeCloseListener(ActionListener l)
l
- The close listenerpublic void addBackListener(ActionListener l)
l
- Listenerpublic void removeBackListener(ActionListener l)
l
- The close listener