Class InputBox


  • public class InputBox
    extends Window
    This class pops up a Window with a Label, an Edit and some buttons. Good to input some text from the user. Here is an example (taken from examples/apps/GuiBuilder):
        // on some event...
          if (renameDialog == null)
             renameDialog = new InputBox("Project Rename","Please enter the new name which will be used for the project:","");
          renameDialog.setValue(projectName);
          renameDialog.popup();
          // when window closes...
          if (renameDialog.getPressedButtonIndex() == 0) // ok?
          {
             projectName = renameDialog.getValue();
          }
        
    • Field Detail

      • openKeyboardOnPopup

        public static boolean openKeyboardOnPopup
        Set to true to automatically open the keyboard once the InputBox is open.
        Since:
        TotalCross 1.53
      • yPosition

        public int yPosition
        Defines the y position on screen where this window opens. Can be changed to TOP or BOTTOM. Defaults to CENTER.
        See Also:
        Control.CENTER, Control.TOP, Control.BOTTOM
      • buttonKeys

        public int[] buttonKeys
        If you set the buttonCaptions array in the construction, you can also set this public field to an int array of the keys that maps to each of the buttons. For example, if you set the buttons to {"Ok","Cancel"}, you can map the enter key for the Ok button and the escape key for the Cancel button by assigning:
         buttonKeys = new int[]{SpecialKeys.ENTER,SpecialKeys.ESCAPE};
         
        Note that if you use the default Ok/Cancel buttons, this mapping is already done.
        Since:
        TotalCross 1.27
    • Constructor Detail

      • InputBox

        public InputBox​(java.lang.String title,
                        java.lang.String text,
                        java.lang.String defaultValue)
        Creates a new InputBox with the given window Title, the given label Text, the given Default value for the Edit, and two buttons "Ok" and "Cancel". The text used in a Label can be multi-line. If the text is too big, it will be splitted.
      • InputBox

        public InputBox​(java.lang.String title,
                        java.lang.String text,
                        java.lang.String defaultValue,
                        java.lang.String[] buttonCaptions)
        Creates a new InputBox with the given window Title, the given label Text, the given Default value for the Edit and with the given buttons. The text used in a Label can be multi-line. If the text is too big, it will be splitted.
      • InputBox

        public InputBox​(java.lang.String title,
                        java.lang.String text,
                        java.lang.String defaultValue,
                        java.lang.String[] buttonCaptions,
                        boolean allSameWidth,
                        int gap,
                        int insideGap)
        Creates a new InputBox with the given window Title, the given label Text, the given Default value for the Edit and with the given buttons. The text used in a Label can be multi-line. If the text is too big, it will be splitted.
    • Method Detail

      • onPopup

        protected void onPopup()
        Description copied from class: Window
        Placeholder called imediatly before the popup began. The default implementation does nothing.
        Overrides:
        onPopup in class Window
      • setTextAlignment

        public void setTextAlignment​(int align)
        Sets the alignment for the text. Must be CENTER (default), LEFT or RIGHT
      • reposition

        public void reposition()
        Description copied from class: Control
        Reposition this control, calling again setRect with the original parameters.
        Overrides:
        reposition in class Control
      • postPopup

        protected void postPopup()
        Description copied from class: Window
        Placeholder called after the popup is done and after the repaint of this window. The default implementation does nothing.
        Overrides:
        postPopup in class Window
      • postUnpop

        protected void postUnpop()
        Description copied from class: Window
        Placeholder called after the unpop is done and after the repaint of the other window. The default implementation does nothing.
        Overrides:
        postUnpop in class Window
      • getPressedButtonIndex

        public int getPressedButtonIndex()
        Returns the pressed button index, starting from 0
      • getValue

        public java.lang.String getValue()
        Returns the value entered
      • setValue

        public void setValue​(java.lang.String value)
        Sets the default value on the Edit field
      • getEdit

        public Edit getEdit()
        Returns the Edit so you can set its properties.
      • setEdit

        public void setEdit​(Edit ed)
        Sets the Edit to the given one.