Class SpanMultiButton

All Implemented Interfaces:
Animation, Editable, ActionSource, StyleListener, IconHolder, SelectableIconHolder, TextHolder, Iterable<Component>

public class SpanMultiButton extends Container implements ActionSource, SelectableIconHolder, TextHolder

A powerful button like component that allows multiple rows/and an icon to be added every row/icon can have its own UIID. Internally the multi-button is a container with a lead component. Up to 4 rows are supported.

It's like MultiButton, but it breaks lines.

Form hi = new Form("Test SpanMultiButton", BoxLayout.y());

Image icon = FontImage.createMaterial(FontImage.MATERIAL_WARNING, "Button", 3.0f);
Image emblem = FontImage.createMaterial(FontImage.MATERIAL_ARROW_FORWARD, "Button", 3.0f);

SpanMultiButton twoLinesNoIcon = new SpanMultiButton("SpanMultiButton");
twoLinesNoIcon.setTextLine2("Line 2 long - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
SpanMultiButton oneLineIconEmblem = new SpanMultiButton("Icon + Emblem");
oneLineIconEmblem.setIcon(icon);
oneLineIconEmblem.setEmblem(emblem);
SpanMultiButton twoLinesIconEmblem = new SpanMultiButton("Icon + Emblem");
twoLinesIconEmblem.setIcon(icon);
twoLinesIconEmblem.setEmblem(emblem);
twoLinesIconEmblem.setTextLine2("Line 2 long - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");

SpanMultiButton twoLinesIconEmblemHorizontal = new SpanMultiButton("Icon + Emblem");
twoLinesIconEmblemHorizontal.setIcon(icon);
twoLinesIconEmblemHorizontal.setEmblem(emblem);
twoLinesIconEmblemHorizontal.setTextLine2("Line 2 Horizontal");
twoLinesIconEmblemHorizontal.setHorizontalLayout(true);

SpanMultiButton twoLinesIconCheckBox = new SpanMultiButton("CheckBox");
twoLinesIconCheckBox.setIcon(icon);
twoLinesIconCheckBox.setCheckBox(true);
twoLinesIconCheckBox.setTextLine2("Line 2 long - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");

SpanMultiButton fourLinesIcon = new SpanMultiButton("With Icon");
fourLinesIcon.setIcon(icon);
fourLinesIcon.setTextLine2("Line 2 - Lorem ipsum dolor sit amet, consectetur adipiscing elit");
fourLinesIcon.setTextLine3("Line 3 - sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
fourLinesIcon.setTextLine4("Line 4 - Excepteur sint occaecat cupidatat non proident");

oneLineIconEmblem.addActionListener(l -> ToastBar.showInfoMessage("Hello 1"));
twoLinesNoIcon.addActionListener(l -> ToastBar.showInfoMessage("Hello 2"));
twoLinesIconEmblem.addActionListener(l -> ToastBar.showInfoMessage("Hello 3"));
twoLinesIconEmblemHorizontal.addActionListener(l -> ToastBar.showInfoMessage("Hello 4"));
twoLinesIconCheckBox.addActionListener(l -> ToastBar.showInfoMessage("Hello 5"));
fourLinesIcon.addActionListener(l -> ToastBar.showInfoMessage("Hello 6"));

hi.add(oneLineIconEmblem).
add(twoLinesNoIcon).
add(twoLinesIconEmblem).
add(twoLinesIconEmblemHorizontal).
add(twoLinesIconCheckBox).
add(fourLinesIcon);
hi.show();
  • Constructor Details

    • SpanMultiButton

      public SpanMultiButton(String line1)

      Initializes a multibutton with the first line of text

      Parameters
      • line1: first line of text
    • SpanMultiButton

      public SpanMultiButton()
      Default constructor allowing the designer to create an instance of this class
  • Method Details

    • isLinesTogetherMode

      public boolean isLinesTogetherMode()
      Indicates if the lines are grouped together on this button
    • setLinesTogetherMode

      public void setLinesTogetherMode(boolean l)

      Changes the layout so the lines of the button are grouped together

      Parameters
      • l: true to group the lines together
    • getIconComponent

      public Label getIconComponent()

      Allows us to gain direct access to the icon component so we can set it directly without going via the other methods, this is especially useful for classes such as the ImageDownloadService which can then update the icon seamlessly.

      Returns

      the component used internally to represent the icon

    • addActionListener

      public void addActionListener(ActionListener al)

      Adds an action listener

      Parameters
      • al: the action listener
      Specified by:
      addActionListener in interface ActionSource
    • removeActionListener

      public void removeActionListener(ActionListener al)

      Removes an action listener

      Parameters
      • al: the action listener
      Specified by:
      removeActionListener in interface ActionSource
    • addLongPressListener

      public void addLongPressListener(ActionListener l)

      Adds a listener to the pointer event

      Parameters
      • l: callback to receive pointer events
      Since

      7.0

      Parameters
      • l
      Overrides:
      addLongPressListener in class Component
    • removeLongPressListener

      public void removeLongPressListener(ActionListener l)

      Removes the listener from the pointer event

      Parameters
      • l: callback to remove
      Since

      7.0

      Parameters
      • l
      Overrides:
      removeLongPressListener in class Component
    • addPointerPressedListener

      public void addPointerPressedListener(ActionListener l)

      Adds a listener to the pointer event

      Parameters
      • l: callback to receive pointer events
      Parameters
      • l
      Overrides:
      addPointerPressedListener in class Component
    • removePointerPressedListener

      public void removePointerPressedListener(ActionListener l)

      Removes the listener from the pointer event

      Parameters
      • l: callback to remove
      Parameters
      • l
      Overrides:
      removePointerPressedListener in class Component
    • addPointerReleasedListener

      public void addPointerReleasedListener(ActionListener l)

      Adds a listener to the pointer event

      Parameters
      • l: callback to receive pointer events
      Parameters
      • l
      Overrides:
      addPointerReleasedListener in class Component
    • removePointerReleasedListener

      public void removePointerReleasedListener(ActionListener l)

      Removes the listener from the pointer event

      Parameters
      • l: callback to remove
      Parameters
      • l
      Overrides:
      removePointerReleasedListener in class Component
    • getCommand

      public Command getCommand()

      Returns the command for the emblem

      Returns

      the command instance

    • setCommand

      public void setCommand(Command c)

      Sets the command for the component, it doesn't affe

      Parameters
      • c: the command
    • isCheckBox

      public boolean isCheckBox()

      Returns true if this is a checkbox button

      Returns

      true for a checkbox button

    • setCheckBox

      public void setCheckBox(boolean b)

      Turns the multi-button into a checkbox multi-button

      Parameters
      • b: true for a checkbox multi-button
    • isRadioButton

      public boolean isRadioButton()

      Returns true if this is a radio button

      Returns

      true for a radio button

    • setRadioButton

      public void setRadioButton(boolean b)

      Turns the multi-button into a radio multi-button

      Parameters
      • b: true for a radio multi-button
    • isSelected

      public boolean isSelected()

      Returns true if the checkbox/radio button is selected

      Returns

      true if the checkbox/radio button is selected

    • setSelected

      public void setSelected(boolean b)

      Toggles the selected state for the radio button/check box modes

      Parameters
      • b: true for checked false for unchecked
    • isHorizontalLayout

      public boolean isHorizontalLayout()

      Indicates whether the first two labels are be side by side

      Returns

      true if the first two labels are side by side

    • setHorizontalLayout

      public void setHorizontalLayout(boolean b)

      Indicates the first two labels should be side by side

      Parameters
      • b: true to place the first two labels side by side
    • isInvertFirstTwoEntries

      public boolean isInvertFirstTwoEntries()

      Inverts the order of the first two entries so the second line appears first. This only works in horizontal mode!

      Returns

      true when the second row entry should be placed before the first entry

    • setInvertFirstTwoEntries

      public void setInvertFirstTwoEntries(boolean b)

      Inverts the order of the first two entries so the second line appears first. This only works in horizontal mode!

      Parameters
      • b: true to place the second row entry as the first entry
    • getTextLine1

      public String getTextLine1()

      Returns the content of the row

      Returns

      the text

    • setTextLine1

      public void setTextLine1(String t)

      Sets the content of the row

      Parameters
      • t: text to set
    • getNameLine1

      public String getNameLine1()

      Returns the name of the row

      Returns

      the name

    • setNameLine1

      public void setNameLine1(String t)

      Sets the name of the row (important for use in generic renderers)

      Parameters
      • t: name to set
    • getUIIDLine1

      public String getUIIDLine1()

      Returns the UIID of the row

      Returns

      the UIID

    • setUIIDLine1

      public void setUIIDLine1(String t)

      Sets the UIID of the row

      Parameters
      • t: UIID to set
    • getTextLine2

      public String getTextLine2()

      Returns the content of the row

      Returns

      the text

    • setTextLine2

      public void setTextLine2(String t)

      Sets the content of the row

      Parameters
      • t: text to set
    • getNameLine2

      public String getNameLine2()

      Returns the name of the row

      Returns

      the name

    • setNameLine2

      public void setNameLine2(String t)

      Sets the name of the row (important for use in generic renderers

      Parameters
      • t: name to set
    • getUIIDLine2

      public String getUIIDLine2()

      Returns the UIID of the row

      Returns

      the UIID

    • setUIIDLine2

      public void setUIIDLine2(String t)

      Sets the UIID of the row

      Parameters
      • t: UIID to set
    • removeTextLine1

      public void removeTextLine1()
      Removes the content of the row
    • removeTextLine2

      public void removeTextLine2()
      Removes the content of the row
    • removeTextLine3

      public void removeTextLine3()
      Removes the content of the row
    • removeTextLine4

      public void removeTextLine4()
      Removes the content of the row
    • getTextLine3

      public String getTextLine3()

      Returns the content of the row

      Returns

      the text

    • setTextLine3

      public void setTextLine3(String t)

      Sets the content of the row

      Parameters
      • t: text to set
    • getNameLine3

      public String getNameLine3()

      Returns the name of the row

      Returns

      the name

    • setNameLine3

      public void setNameLine3(String t)

      Sets the name of the row (important for use in generic renderers

      Parameters
      • t: name to set
    • getUIIDLine3

      public String getUIIDLine3()

      Returns the UIID of the row

      Returns

      the UIID

    • setUIIDLine3

      public void setUIIDLine3(String t)

      Sets the UIID of the row

      Parameters
      • t: UIID to set
    • getTextLine4

      public String getTextLine4()

      Returns the content of the row

      Returns

      the text

    • setTextLine4

      public void setTextLine4(String t)

      Sets the content of the row

      Parameters
      • t: text to set
    • getNameLine4

      public String getNameLine4()

      Returns the name of the row

      Returns

      the name

    • setNameLine4

      public void setNameLine4(String t)

      Sets the name of the row (important for use in generic renderers

      Parameters
      • t: name to set
    • getUIIDLine4

      public String getUIIDLine4()

      Returns the UIID of the row

      Returns

      the UIID

    • setUIIDLine4

      public void setUIIDLine4(String t)

      Sets the UIID of the row

      Parameters
      • t: UIID to set
    • getIcon

      public Image getIcon()

      Returns the icon image

      Returns

      the image instance

      Specified by:
      getIcon in interface IconHolder
    • setIcon

      public void setIcon(Image i)

      Sets the icon

      Parameters
      • i: the icon
      Specified by:
      setIcon in interface IconHolder
    • getEmblem

      public Image getEmblem()

      Returns the emblem image

      Returns

      the image instance

    • setEmblem

      public void setEmblem(Image i)

      Sets the emblem

      Parameters
      • i: the icon
    • getIconPosition

      public String getIconPosition()

      Returns the icon position based on border layout constraints

      Returns

      position either North/South/East/West

    • setIconPosition

      public void setIconPosition(String t)

      Sets the icon position based on border layout constraints

      Parameters
      • t: position either North/South/East/West
    • getEmblemPosition

      public String getEmblemPosition()

      Returns the emblem position based on border layout constraints

      Returns

      position either North/South/East/West

    • setEmblemPosition

      public void setEmblemPosition(String t)

      Sets the emblem position based on border layout constraints

      Parameters
      • t: position either North/South/East/West
    • getIconName

      public String getIconName()

      Returns the name of the icon

      Returns

      the name

    • setIconName

      public void setIconName(String t)

      Sets the name of the icon (important for use in generic renderers

      Parameters
      • t: name to set
    • getIconUIID

      public String getIconUIID()

      Returns the UIID of the Icon

      Returns

      the UIID

      Specified by:
      getIconUIID in interface IconHolder
    • setIconUIID

      public void setIconUIID(String t)

      Sets the UIID of the icon

      Parameters
      • t: UIID to set
      Specified by:
      setIconUIID in interface IconHolder
    • getEmblemName

      public String getEmblemName()

      Returns the name of the emblem

      Returns

      the name

    • setEmblemName

      public void setEmblemName(String t)

      Sets the name of the emblem (important for use in generic renderers

      Parameters
      • t: name to set
    • getEmblemUIID

      public String getEmblemUIID()

      Returns the UIID of the Emblem

      Returns

      the UIID

    • setEmblemUIID

      public void setEmblemUIID(String t)

      Sets the UIID of the emblem

      Parameters
      • t: UIID to set
    • getPropertyNames

      public String[] getPropertyNames()

      A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code

      Returns

      the property names allowing mutation

      Overrides:
      getPropertyNames in class Component
    • getPropertyTypes

      public Class[] getPropertyTypes()

      Matches the property names method (see that method for further details).

      Returns

      the types of the properties

      Overrides:
      getPropertyTypes in class Component
    • getPropertyValue

      public Object getPropertyValue(String name)

      Returns the current value of the property name, this method is used by the GUI builder

      Parameters
      • name: the name of the property
      Returns

      the value of said property

      Overrides:
      getPropertyValue in class Component
    • getText

      public String getText()

      Sets the line 1 text

      The text of the component

      Returns

      the text

      Specified by:
      getText in interface TextHolder
    • setText

      public void setText(String text)

      Returns the line 1 text

      New text for the component

      Parameters
      • text: the text
      Specified by:
      setText in interface TextHolder
    • setPropertyValue

      public String setPropertyValue(String name, Object value)

      Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as "$designMode" might be sent to components to indicate application state.

      Parameters
      • name: the name of the property

      • value: new value for the property

      Returns

      error message or null

      Overrides:
      setPropertyValue in class Component
    • getGroup

      public String getGroup()

      Indicates the group for the radio button

      Returns

      the group

    • setGroup

      public void setGroup(String group)

      Indicates the group for the radio button

      Parameters
      • group: the group to set
    • setGroup

      public void setGroup(ButtonGroup bg)

      Sets the button group for a radio button mode multibutton

      Parameters
      • bg: the button group
    • getMaskName

      public String getMaskName()

      Set the mask name for the icon

      Returns

      the maskName

    • setMaskName

      public void setMaskName(String maskName)

      The mask name for the icon

      Parameters
      • maskName: the maskName to set
    • isShouldLocalize

      public boolean isShouldLocalize()

      Indicates if text should be localized when set to the component, by default all text is localized so this allows disabling automatic localization for a specific component.

      Returns

      the shouldLocalize value

    • setShouldLocalize

      public void setShouldLocalize(boolean shouldLocalize)

      Indicates if text should be localized when set to the component, by default all text is localized so this allows disabling automatic localization for a specific component.

      Parameters
      • shouldLocalize: the shouldLocalize to set
    • getGap

      public int getGap()

      Returns the gap in pixels between the icon/text to the Label boundaries

      Returns

      the gap in pixels between the icon/text to the Label boundaries

      Since

      7.0

      Specified by:
      getGap in interface IconHolder
    • setGap

      public void setGap(int gap)

      Set the gap in pixels between the icon/text to the Label boundaries

      Parameters
      • gap: the gap in pixels
      Since

      7.0

      Specified by:
      setGap in interface IconHolder
    • getTextPosition

      public int getTextPosition()

      Returns The position of the text relative to the icon

      Returns

      The position of the text relative to the icon, one of: LEFT, RIGHT, BOTTOM, TOP

      See also
      • #LEFT

      • #RIGHT

      • #BOTTOM

      • #TOP

      Since

      7.0

      Specified by:
      getTextPosition in interface IconHolder
    • setTextPosition

      public void setTextPosition(int textPosition)

      Sets the position of the text relative to the icon if exists

      Parameters
      • textPosition: alignment value (LEFT, RIGHT, BOTTOM or TOP)
      See also
      • #LEFT

      • #RIGHT

      • #BOTTOM

      • #TOP

      Since

      7.0

      Specified by:
      setTextPosition in interface IconHolder
    • getIconStyleComponent

      public Component getIconStyleComponent()
      Description copied from interface: IconHolder

      Gets the component that should be used for styling material the material icon. If #setIconUIID(java.lang.String) has been used to set a custom UIID for the icon, then this will return a component with that UIID. Otherwise this will just return this component itself.

      Returns

      The component to use for styling the material icon.

      Since

      7.0

      Specified by:
      getIconStyleComponent in interface IconHolder
    • setMaterialIcon

      public void setMaterialIcon(char c, float size)

      This method is shorthand for char, float)

      Parameters
      • c: one of the constants from com.codename1.ui.FontImage

      • size: the size of the icon in millimeters

      Since

      8.0

      Since

      8.0

      Specified by:
      setMaterialIcon in interface IconHolder
    • setFontIcon

      public void setFontIcon(Font font, char c, float size)

      This method is shorthand for com.codename1.ui.Font, char, float)

      Parameters
      • c: one of the constants from the font

      • size: the size of the icon in millimeters

      Since

      8.0

      Since

      8.0

      Specified by:
      setFontIcon in interface IconHolder
    • getRolloverIcon

      public Image getRolloverIcon()

      Indicates the icon that is displayed on the button when the button is in rolled over state

      Returns

      icon used

      See also
      • Button#STATE_ROLLOVER
      Since

      7.0

      Specified by:
      getRolloverIcon in interface SelectableIconHolder
    • setRolloverIcon

      public void setRolloverIcon(Image arg0)

      Indicates the icon that is displayed on the button when the button is in rolled over state

      Parameters
      • rolloverIcon: icon to use
      See also
      • Button#STATE_ROLLOVER
      Since

      7.0

      Specified by:
      setRolloverIcon in interface SelectableIconHolder
    • getPressedIcon

      public Image getPressedIcon()

      Indicates the icon that is displayed on the button when the button is in pressed state

      Returns

      icon used

      See also
      • Button#STATE_PRESSED
      Since

      7.0

      Specified by:
      getPressedIcon in interface SelectableIconHolder
    • setPressedIcon

      public void setPressedIcon(Image arg0)

      Indicates the icon that is displayed on the button when the button is in pressed state

      Parameters
      • pressedIcon: icon used
      See also
      • Button#STATE_PRESSED
      Since

      7.0

      Specified by:
      setPressedIcon in interface SelectableIconHolder
    • getDisabledIcon

      public Image getDisabledIcon()

      Indicates the icon that is displayed on the button when the button is in the disabled state

      Returns

      icon used

      Since

      7.0

      Specified by:
      getDisabledIcon in interface SelectableIconHolder
    • setDisabledIcon

      public void setDisabledIcon(Image arg0)

      Indicates the icon that is displayed on the button when the button is in the disabled state

      Parameters
      • disabledIcon: icon used
      Since

      7.0

      Specified by:
      setDisabledIcon in interface SelectableIconHolder
    • getRolloverPressedIcon

      public Image getRolloverPressedIcon()

      Indicates the icon that is displayed on the button when the button is in pressed state and is selected. This is ONLY applicable to toggle buttons

      Returns

      icon used

      Since

      7.0

      Specified by:
      getRolloverPressedIcon in interface SelectableIconHolder
    • setRolloverPressedIcon

      public void setRolloverPressedIcon(Image icn)

      Indicates the icon that is displayed on the button when the button is in pressed state and is selected. This is ONLY applicable to toggle buttons

      Parameters
      • rolloverPressedIcon: icon used
      Since

      7.0

      Specified by:
      setRolloverPressedIcon in interface SelectableIconHolder
    • getIconFromState

      public Image getIconFromState()

      Returns the icon for the button based on its current state

      Returns

      the button icon based on its current state

      Since

      7.0

      Specified by:
      getIconFromState in interface SelectableIconHolder