Class Button

All Implemented Interfaces:
Animatable<Button>, CanDrop<Button>, Clickable<Button>, Draggable<Button>, HandleHotKey<Button>, HandleMouseEvents<Button>, Touchable<Button>

Button component

With this component, a button can be placed on the interface. The button can be customized, and it can have an icon and/or text on it. The click event handler can be implemented on the server side.

The button component supports the use of animations, that can be used when the button appears or disappears. The animation can be set by using the setAnimation method. For the types of animation, see the Animation enum.

A counter can also be placed on the right side of the button. The counter can have any integer number in it. This can be used to count content, for example, the amount of unread messages

Supported events:

AnimationEnd, Click, DoubleClick, MouseDown, MouseDown, MouseLeave, MouseMove, MouseOver, MouseOut, MouseUp, Wheel, TouchCancel, TouchEnd, TouchMove, TouchStart, HotKey Drop, DragStart, DragEnd

Since:
4.0
Author:
JBStrap
  • Field Details

    • text

      protected String text
    • icon

      protected Icon icon
    • image

      protected Image image
  • Constructor Details

    • Button

      public Button(Icon icon)
      creates a button with the specified icon
      Parameters:
      icon - the icon of the button. for the applicable icons, see the Icon enum.
      Throws:
      IllegalStateException - if the component is set to be both private and public, through an annotation.
    • Button

      public Button(String id, Icon icon)
      Creates a button with the specified icon
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Button

      public Button(String text)
      Creates a button with the specified text
      Parameters:
      text - The button text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Button

      public Button(String id, String text)
      Creates a button with the specified text
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      text - The button text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Button

      public Button(Icon icon, String text)
      Creates a button with the specified icon and text
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Button

      public Button(String id, Icon icon, String text)
      Creates a button with the specified icon and text
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Button

      public Button(String text, StyleElement... styles)
      Creates a button with the specified text and style(s).
      Parameters:
      text - The button text
      styles - The style (type and/or size) of the button. For the applicable types, see the ButtonType enum. For the applicable sizes, see the ButtonSize enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Button

      public Button(Icon icon, String text, StyleElement... styles)
      Creates a button with the specified icon, text and style(s).
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      styles - The style (type and/or size) of the button. For the applicable types, see the ButtonType enum. For the applicable sizes, see the ButtonSize enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Button

      public Button(String id, Icon icon, String text, StyleElement... styles)
      Creates a button with the specified icon, text and style(s).
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      styles - The style (type and/or size) of the button. For the applicable types, see the ButtonType enum. For the applicable sizes, see the ButtonSize enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
  • Method Details

    • setText

      public Button setText(String text)
      Sets the button text
      Parameters:
      text - The button text
      Returns:
      The button component
    • getText

      public String getText()
      Gets the button text
      Returns:
      The current button text. If it has no text, returns with null
    • setIcon

      public Button setIcon(Icon icon)
      Sets the button icon
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      Returns:
      The button component
    • getIcon

      public Icon getIcon()
      Gets the button icon
      Returns:
      The current button icon. If it has no icon, returns with null
    • setImage

      public Button setImage(Image image)
      Places an image on the button
      Parameters:
      image - The image that will be on the button. If specified as null, nothing will be placed.
      Returns:
      The button component
    • setType

      public Button setType(ButtonType type)
      Sets the button size
      Parameters:
      type - The size of the button. For the applicable types, see the ButtonType enum.
      Returns:
      The button
    • setSize

      public Button setSize(ButtonSize size)
      Stets the button size
      Parameters:
      size - The style size of the button. For the applicable types, see the ButtonSize enum.
      Returns:
      The button
    • setCounter

      public final Button setCounter(long value)
      Adds a counter to the right side of the button.
      Parameters:
      value - The counter value
      Returns:
      The button component
    • getCounter

      public final long getCounter()
      Gets the counter value
      Returns:
      The current value on the button counter. If the button has no counter, returns with -1.
    • setRounded

      public Button setRounded(boolean rounded)
      Toggles on/off the roundedness of a button.
      Parameters:
      rounded - If true is specified, the button is displayed as a rounded button, Otherwise it is rectangular
      Returns:
      The button
    • isRounded

      public boolean isRounded()
      Checks if the button is rounded.
      Returns:
      If true is specified, the button is displayed as a rounded button, otherwise rectangular
    • writeHTML

      public boolean writeHTML(StringWriter writer)
      Description copied from class: Component
      Creates the component's HTML equivalent

      This method doesn't need to be used during application development. This method is used when developing a custom component. When creating a custom component, this method needs to be implemented. In the parameter (StringWriter class) the component's HTML equivalent must be specified, and the method has to return with a Boolean value. This boolean value determines if the component was drawn. If the user doesn't have access right to the component, or if the component couldn't be drawn, it should return with false. Otherwise, it must return with true.

      Specified by:
      writeHTML in class Component<Button>
      Returns:
      If the componentwas drawn, true, otherwise false