Package totalcross.ui

Class PopupMenu


  • public class PopupMenu
    extends Window
    Creates a popup menu with a single line list and some radio buttons at right, like in the Android combobox styles. This is a sample of how to use it:
     String[] items = { "Always", "Never", "Only in Silent mode", "Only when not in Silent mode",
                    "Non of the answers above", };
     PopupMenu pm = new PopupMenu("Vibrate", items);
     pm.popup();
     
    A PRESSED event is sent when an item is selected. Note: the colors must be set before the control's bounds are defined using setRect or add.
    • Field Detail

      • cancelString

        public static java.lang.String cancelString
        The string of the button; defaults to "Cancel"
      • dataCol

        public int dataCol
        If the items is a String matrix (String[][]), this field sets the column that will be shown.
      • itemCount

        public int itemCount
        Sets the number of elements should be used from the items array passed in the constructor. Defaults to items.length.
      • checkColor

        public int checkColor
        The check color used to fill the radio button used in Android. Defaults to the fore color.
        Since:
        TotalCross 1.3
      • enableSearch

        public boolean enableSearch
        Set to true BEFORE popping up the window to enable search on the items of this PopupMenu. Note that it only works if the items are ORDERED.
        Since:
        TotalCross 1.5
      • enableCancel

        public boolean enableCancel
        Set to false BEFORE popping up the window to disable the Cancel button.
        Since:
        TotalCross 1.65
      • keepIndexOnCancel

        public boolean keepIndexOnCancel
        Set to true to keep the selected index unchanged if user press the Cancel button
        Since:
        TotalCross 2.0
    • Method Detail

      • onClickedOutside

        public boolean onClickedOutside​(PenEvent event)
        Description copied from class: Window
        called when the user clicks outside the bounds of this window. must return true if the event was handled, false otherwise. If false is returned and beepIfOut is true, then a beep is played and nothing more happens.
        Overrides:
        onClickedOutside in class Window
      • initUI

        public void initUI()
        Description copied from class: Container
        Called to initialize the User Interface of this container. This differs from the onAddAgain method by that this method is called only once, at the first time the control is added to the parent. When the container is being setup, the initUI method is called; then, the onAddAgain is called every time the container is added again.
        Overrides:
        initUI in class Container
      • reposition

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

        public void onEvent​(Event event)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • 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
      • setTitle

        public void setTitle​(java.lang.String title)
        Description copied from class: Window
        Sets the title and call repaint.
        Overrides:
        setTitle in class Window
      • getPreferredWidth

        public int getPreferredWidth()
        Description copied from class: Window
        Returns the size of the title if any plus the size of the border. Note that the value returned here does not handle the controls inside the window.
        Overrides:
        getPreferredWidth in class Window
      • getPreferredHeight

        public int getPreferredHeight()
        Description copied from class: Window
        Returns the size of the title if any plus the size of the border. Note that the value returned here does not handle the controls inside the window.
        Overrides:
        getPreferredHeight in class Window
      • getMenu

        public ListBox getMenu()
        Returns the ListBox used to show the menu. You can edit the paddings the way you want calling this method.
      • getSelectedItem

        public java.lang.Object getSelectedItem()
      • setSelectedIndex

        public int setSelectedIndex​(int index)
        Selects the given index.
      • getSelectedIndex

        public int getSelectedIndex()
        Returns the selected index when this window was closed or -1 if non was selected
      • popupAt

        public void popupAt​(int x,
                            int y,
                            int width,
                            int height)
      • popupAt

        public void popupAt​(int x,
                            int y)
      • onPopup

        protected void onPopup()
        Setup some important variables
        Overrides:
        onPopup 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
      • setCursorColor

        public void setCursorColor​(int c)
        Sets the cursor color. By default, it is based in the background color