Package totalcross.ui

Class MultiButton


  • public class MultiButton
    extends Control
    MultiButton is a control that displays a single line button with a set of titles. Can be used to replace a Check (with on/off) or a Radio (with their options). Sample:
     MultiButton b = new MultiButton(new String[]{"+","-"});
       b.setBackColor(Color.CYAN);
       add(b,LEFT+50,TOP+50,200,FONTSIZE+150);
     
    Since:
    TotalCross 2.0
    • Field Detail

      • divColor

        public int divColor
        The color used to divide the texts.
      • selColor

        public int selColor
        The selection color.
      • is3dText

        public boolean is3dText
        Defines if the text will have a 3d style.
      • isSticky

        public boolean isSticky
        Set to true to behave like a Radio, false like a Button
    • Constructor Detail

      • MultiButton

        public MultiButton​(java.lang.String[] captions)
        Constructs a MultiButton with the given captions.
    • Method Detail

      • onColorsChanged

        public void onColorsChanged​(boolean colorsChanged)
        Description copied from class: Control
        Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
        Overrides:
        onColorsChanged in class Control
      • onBoundsChanged

        public void onBoundsChanged​(boolean colorsChanged)
        Description copied from class: Control
        Called after a setRect.
        Overrides:
        onBoundsChanged in class Control
        Parameters:
        colorsChanged - If the bounds were changed due to a screen change (rotation, collapse)
      • setSelectedIndex

        public void setSelectedIndex​(int sel)
        Sets the selected index, or -1 to unset it. Only an enabled index can be selected.
      • setEnabled

        public void setEnabled​(int idx,
                               boolean enabled)
        Enables or disables a caption
      • isEnabled

        public boolean isEnabled​(int idx)
        Returns if a caption is enabled or not
      • getSelectedIndex

        public int getSelectedIndex()
        Returns the selected index
      • onPaint

        public void onPaint​(Graphics g)
        Description copied from class: Control
        Called to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted.
        Overrides:
        onPaint in class Control
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • onEvent

        public void onEvent​(Event e)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        e - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • getPreferredHeight

        public int getPreferredHeight()
        Description copied from class: Control
        Returns the preferred height of this control.
        Overrides:
        getPreferredHeight in class Control
      • getPreferredWidth

        public int getPreferredWidth()
        Description copied from class: Control
        Returns the preferred width of this control.
        Overrides:
        getPreferredWidth in class Control