Class Sheet

All Implemented Interfaces:
Animation, Editable, StyleListener, Iterable<Component>

public class Sheet extends Container

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
  • Constructor Details

    • Sheet

      public Sheet(Sheet parent, String title)

      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

      public Sheet(Sheet parent, String title, String uiid)

      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

      public static Sheet 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

      public static Sheet findContainingSheet(Component cmp)

      Finds Sheet containing this component if it is currently part of a Sheet.

      Parameters
      • cmp: The component to check.
      Returns

      The sheet containing the component, or null if it is not on a sheet.

      Since

      7.0

    • 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

      public Container 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

      public Container 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

      public String 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

      public void setPosition(String position)

      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 of 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)

    • setPosition

      public void setPosition(String phonePosition, String tabletPosition)

      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 of BorderLayout#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: Component

      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.

      Parameters
      • x: the current x coordinate of the components origin
      Overrides:
      setX in class Component
    • setY

      public void setY(int y)
      Description copied from class: Component

      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.

      Parameters
      • y: the current y coordinate of the components origin
      Overrides:
      setY in class Component
    • setWidth

      public void setWidth(int width)
      Description copied from class: Component

      Sets 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
      Overrides:
      setWidth in class Component
    • setHeight

      public void setHeight(int height)
      Description copied from class: Component

      Sets 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
      Overrides:
      setHeight in class Component
    • getParentSheet

      public Sheet 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: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      Invoked 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:
      deinitialize in class Component
    • isAncestorSheetOf

      public boolean isAncestorSheetOf(Sheet sheet)

      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

      public void addCloseListener(ActionListener l)

      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

      public void removeCloseListener(ActionListener l)

      Removes a close listener.

      Parameters
      • l: The close listener
    • addBackListener

      public void addBackListener(ActionListener l)

      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

      public void removeBackListener(ActionListener l)

      Removes a back listener.

      Parameters
      • l: The close listener