Class SpanButton

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

public class SpanButton extends Container implements ActionSource<ActionEvent>, SelectableIconHolder, TextHolder

A complex button similar to MultiButton that breaks lines automatically and looks like a regular button (more or less). Unlike the multi button the span button has the UIID style of a button.

SpanButton sb = new SpanButton("SpanButton is a composite component (lead component) that looks/acts like a Button but can break lines rather than crop them when the text is very long.");
sb.setIcon(icon);
hi.add(sb);
  • Constructor Details

    • SpanButton

      public SpanButton()
      Default constructor will be useful when adding this to the GUI builder
    • SpanButton

      public SpanButton(String txt, String textUiid)

      Constructor accepting default text and uiid for the text

      Parameters
      • txt: the text

      • textUiid: the new text UIID

    • SpanButton

      public SpanButton(String txt)
      Constructor accepting default text
  • Method Details

    • styleChanged

      public void styleChanged(String propertyName, Style source)
      Description copied from class: Component

      Invoked to indicate a change in a propertyName of a Style

      NOTE By default this will trigger a call to Container#revalidate() on the parent container, which is expensive. You can disable this behavior by calling CN.setProperty("Component.revalidateOnStyleChange", "false"). The intention is to change this behavior so that the default is to "not" revalidate on style change, so we encourage you to set this to "false" to ensure for future compatibility.

      Parameters
      • propertyName: the property name that was changed

      • source: The changed Style object

      Specified by:
      styleChanged in interface StyleListener
      Overrides:
      styleChanged in class Component
    • initUnselectedStyle

      protected void initUnselectedStyle(Style unselectedStyle)
      Description copied from class: Component

      Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

      Parameters
      • unselectedStyle: The unselected style.
      Since

      8.0

      Overrides:
      initUnselectedStyle in class Component
    • getTextComponent

      public TextArea getTextComponent()

      Returns the TextArea holding the actual text

      Returns

      the component

    • getTextUIID

      public String getTextUIID()

      Returns the uiid of the actual text

      Returns

      the uiid

    • setTextUIID

      public void setTextUIID(String uiid)

      Sets the UIID for the actual text

      Parameters
      • uiid: the uiid
    • setUIID

      public void setUIID(String id)
      Description copied from class: Component

      This method sets the Component the Unique identifier. This method should be used before a component has been initialized

      Parameters
      • id: UIID unique identifier for component type
      Overrides:
      setUIID in class Component
    • initLaf

      protected void initLaf(UIManager uim)
      Description copied from class: Container
      This method initializes the Component defaults constants
      Overrides:
      initLaf in class Container
    • getIconStyleComponent

      public Component getIconStyleComponent()

      Gets the component used for styling font icons on this SpanLabel.

      Returns

      The component used for styling font icons on this SpanLabel.

      Since

      7.0

      Specified by:
      getIconStyleComponent in interface IconHolder
    • getTextAllStyles

      public Style getTextAllStyles()

      Returns the Style proxy object for the text of this span button.

      Returns

      The Style object for the text of this span button.

    • getTextStyle

      public Style getTextStyle()

      Returns the Style object for the text of this span button.

      Returns

      The Style object for the text of this span button.

    • getIconUIID

      public String getIconUIID()

      Returns the UIID for the icon

      Returns

      the uiid

      Specified by:
      getIconUIID in interface IconHolder
    • setIconUIID

      public void setIconUIID(String uiid)

      Sets the uiid for the icon if present

      Parameters
      • uiid: the uiid for the icon
      Specified by:
      setIconUIID in interface IconHolder
    • getText

      public String getText()

      Returns the text of the button

      Returns

      the text

      Specified by:
      getText in interface TextHolder
    • setText

      public void setText(String t)

      Set the text of the button

      Parameters
      • t: text of the button
      Specified by:
      setText in interface TextHolder
    • getIcon

      public Image getIcon()

      Returns the image of the icon

      Returns

      the icon

      Specified by:
      getIcon in interface IconHolder
    • setIcon

      public void setIcon(Image i)

      Sets the icon for the button

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

      public void addLongPressListener(ActionListener l)

      Binds long press listener to button events.

      Parameters
      • l
      Since

      7.0

      Overrides:
      addLongPressListener in class Component
    • removeLongPressListener

      public void removeLongPressListener(ActionListener l)

      Unbinds long press listener to button events.

      Parameters
      • l
      Since

      7.0

      Overrides:
      removeLongPressListener in class Component
    • addActionListener

      public void addActionListener(ActionListener<ActionEvent> l)

      Binds an action listener to button events

      Parameters
      • l: the listener
      Specified by:
      addActionListener in interface ActionSource<ActionEvent>
    • removeActionListener

      public void removeActionListener(ActionListener<ActionEvent> l)

      Removes the listener from tracking button events

      Parameters
      • l: the listener
      Specified by:
      removeActionListener in interface ActionSource<ActionEvent>
    • 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
      • s: position either North/South/East/West
    • getCommand

      public Command getCommand()

      Returns the command instance of the button

      Returns

      the command instance of the button

    • setCommand

      public void setCommand(Command cmd)

      Sets the command for the component

      Parameters
      • cmd: the command
    • 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
    • getPropertyTypeNames

      public String[] getPropertyTypeNames()

      This method is here to workaround an XMLVM array type bug where property types aren't identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],Image,Image[],Object[],ListModel,ListCellRenderer

      Returns

      Array of type names

      Overrides:
      getPropertyTypeNames 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
    • 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
    • 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
    • getPressedIcon

      public Image getPressedIcon()

      Returns the pressed icon of the button

      Returns

      the pressed icon

      Specified by:
      getPressedIcon in interface SelectableIconHolder
    • setPressedIcon

      public void setPressedIcon(Image i)

      Sets the pressed icon for the button

      Parameters
      • i: the icon
      Specified by:
      setPressedIcon in interface SelectableIconHolder
    • getRolloverIcon

      public Image getRolloverIcon()

      Returns the rollover icon of the button

      Returns

      the pressed icon

      Specified by:
      getRolloverIcon in interface SelectableIconHolder
    • setRolloverIcon

      public void setRolloverIcon(Image i)

      Sets the rollover icon for the button

      Parameters
      • i: the icon
      Specified by:
      setRolloverIcon in interface SelectableIconHolder
    • getDisabledIcon

      public Image getDisabledIcon()

      Returns the disabled icon of the button

      Returns

      the pressed icon

      Specified by:
      getDisabledIcon in interface SelectableIconHolder
    • setDisabledIcon

      public void setDisabledIcon(Image i)

      Sets the disabled icon for the button

      Parameters
      • i: the icon
      Specified by:
      setDisabledIcon in interface SelectableIconHolder
    • isAutoRelease

      public boolean isAutoRelease()

      Returns if this is an auto released Button. Auto released Buttons will are been disarmed when a drag is happening within the Button.

      Returns

      true if it's an auto released Button.

    • setAutoRelease

      public void setAutoRelease(boolean autoRelease)
      Sets the auto released mode of this button, by default it's not an auto released Button
    • setWidth

      public void setWidth(int width)
      Description copied from class: Component

      Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.

      If a user wishes to affect the component size, setPreferredSize should be used.

      Parameters
      • width: the width of the component
      See also
      • #setPreferredSize
      Overrides:
      setWidth in class Component
    • getGap

      public int getGap()
      Description copied from interface: IconHolder

      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

      Specified by:
      getGap in interface IconHolder
    • setGap

      public void setGap(int gap)
      Description copied from interface: IconHolder

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

      Parameters
      • gap: the gap in pixels
      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

      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

      Specified by:
      setTextPosition in interface IconHolder
    • 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 arg0)

      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
    • setFontIcon

      public void setFontIcon(Font font, char c)

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

      Parameters
      • c: one of the constants from the font
    • 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

      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

      Specified by:
      setFontIcon in interface IconHolder
    • getMaterialIcon

      public char getMaterialIcon()

      Returns the material icon assigned to this component or 0 if not applicable

      Returns

      the material icon

    • setMaterialIcon

      public void setMaterialIcon(char c)

      This method is shorthand for char)

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

      public char getFontIcon()

      Returns the font icon assigned to this component or 0 if not applicable

      Returns

      the material icon

    • getMaterialIconSize

      public float getMaterialIconSize()

      Returns the material icon size assigned to this component or 0/-1 if not applicable

      Returns

      the material icon size

    • getFontIconSize

      public float getFontIconSize()

      Returns the icon size assigned to this component or 0/-1 if not applicable

      Returns

      the icon size

    • getIconFont

      public Font getIconFont()

      Returns the font for the icon font or null if not font set

      Returns

      the material icon size