Class MessageBox

  • Direct Known Subclasses:
    ProgressBox

    public class MessageBox
    extends Window
    This class implements a scrollable message box window with customized buttons, delayed unpop and scrolling text.
    for example, to create an automatic unpop after 5 seconds, do:
       MessageBox mb = new MessageBox("TotalCross","TotalCross is the most exciting tool for developing totally cross-platform programs.",null);
       mb.setUnpopDelay(5000);
       mb.popup(mb);
     
    • Field Detail

      • msg

        protected Label msg
      • xa

        protected int xa
      • ya

        protected int ya
      • wa

        protected int wa
      • ha

        protected int ha
      • lgap

        protected int lgap
      • 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 ENTER is also handled as ACTION, since the ENTER key is mapped to ACTION under some platforms.
        Since:
        TotalCross 1.27
      • showExceptionTitle

        public static java.lang.String showExceptionTitle
        Title shown in the showException dialog.
    • Constructor Detail

      • MessageBox

        public MessageBox​(java.lang.String title,
                          java.lang.String msg)
        Constructs a message box with the text and one "Ok" button. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen.
      • MessageBox

        public MessageBox​(java.lang.String title,
                          java.lang.String text,
                          java.lang.String[] buttonCaptions)
        Constructs a message box with the text and the specified button captions. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen. if buttonCaptions is null, no buttons are displayed and you must dismiss the dialog by calling unpop or by setting the delay using setUnpopDelay method
      • MessageBox

        public MessageBox​(java.lang.String title,
                          java.lang.String text,
                          java.lang.String[] buttonCaptions,
                          boolean allSameWidth)
        Constructs a message box with the text and the specified button captions. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen. If buttonCaptions is null, no buttons are displayed and you must dismiss the dialog by calling unpop or by setting the delay using setUnpopDelay method. The parameters allSameWidth is the same as in the constructor for PushButtonGroup.
        Since:
        TotalCross 1.27
      • MessageBox

        public MessageBox​(java.lang.String title,
                          java.lang.String text,
                          java.lang.String[] buttonCaptions,
                          int gap,
                          int insideGap)
        Constructs a message box with the text and the specified button captions. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen. If buttonCaptions is null, no buttons are displayed and you must dismiss the dialog by calling unpop or by setting the delay using setUnpopDelay method. The new parameters gap and insideGap are the same as in the constructor for PushButtonGroup.
        Since:
        SuperWaba 4.11
      • MessageBox

        public MessageBox​(java.lang.String title,
                          java.lang.String text,
                          java.lang.String[] buttonCaptions,
                          boolean allSameWidth,
                          int gap,
                          int insideGap)
        Constructs a message box with the text and the specified button captions. The text may be separated by '\n' as the line delimiters; otherwise, it is automatically splitted if its too big to fit on screen. If buttonCaptions is null, no buttons are displayed and you must dismiss the dialog by calling unpop or by setting the delay using setUnpopDelay method. The parameters allSameWidth, gap and insideGap are the same as in the constructor for PushButtonGroup.
        Since:
        TotalCross 1.27
    • Method Detail

      • setText

        public void setText​(java.lang.String text)
        This method can be used to set the text AFTER the dialog was shown. However, the dialog will not be resized.
        Since:
        TotalCross 1.3
      • onPopup

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

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

        public void setIcon​(Image icon)
                     throws ImageException
        Set an icon to be shown in the MessageBox's title, at left. It only works if there's a title. If you really need an empty title, pass as title a String with a couple of spaces, like " ". The icon's width and height will be set to title's font ascent.
        Throws:
        ImageException
        Since:
        TotalCross 1.3
      • setTextAlignment

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

        public void setUnpopDelay​(int unpopDelay)
        sets a delay for the unpop of this dialog
      • onPaint

        public void onPaint​(Graphics g)
        Description copied from class: Container
        Draws the border (if any). If you override this method, be sure to call super.onPaint(g);, or the border will not be drawn.
        Overrides:
        onPaint in class Container
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • getPressedButtonIndex

        public int getPressedButtonIndex()
        Returns the pressed button index, starting from 0
      • 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
      • showException

        public static void showException​(java.lang.Throwable t,
                                         boolean dumpToConsole)
        Shows the exception, with its name, message and stack trace in a new MessageBox.
        Since:
        TotalCross 1.0
      • onFontChanged

        protected void onFontChanged()
        Description copied from class: Control
        Called after a setFont
        Overrides:
        onFontChanged in class Control
      • setDelayToShowButton

        public void setDelayToShowButton​(int ms)
        Calling this method will make the buttons initially hidden and will show them after the specified number of milisseconds. Here's a sample:
         MessageBox mb = new MessageBox("Novo Tweet!",tweet);
         mb.setDelayToShowButton(7000);
         mb.popup();
         
        Since:
        TotalCross 1.53