Class DropDownButton
- All Implemented Interfaces:
Animatable<DropDownButton>
,CanDrop<DropDownButton>
,Clickable<DropDownButton>
,Draggable<DropDownButton>
,HandleHotKey<DropDownButton>
,HandleMouseEvents<DropDownButton>
,Touchable<DropDownButton>
DropDownButton 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.
Other menu items can be placed on the button, and they will appear to the user when they press the button. The menu items have their own individual click events, that can be programmed individually.
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:
AnimationStart
AnimationEnd
,
Click
,
DoubleClick
,
MouseDown
,
MouseDown
,
MouseLeave
,
MouseMove
,
MouseOver
,
MouseOut
,
MouseUp
,
Wheel
,
TouchCancel
,
TouchEnd
,
TouchMove
,
TouchStart
,
HotKey
Drop
,
DragStart
,
DragEnd
- Since:
- 4.0
- Author:
- JBStrap
-
Nested Class Summary
-
Field Summary
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition
-
Constructor Summary
ConstructorDescriptionDropDownButton
(Icon icon) creates a button with the specified iconDropDownButton
(Icon icon, String text) Creates a button with the specified icon and textDropDownButton
(Icon icon, String text, StyleElement... styles) Creates a button with the specified icon, text and style(s).DropDownButton
(String text) Creates a button with the specified textDropDownButton
(String text, StyleElement... styles) Creates a button with the specified text and style(s).DropDownButton
(String id, Icon icon) Creates a button with the specified iconDropDownButton
(String id, Icon icon, String text) Creates a button with the specified icon and textDropDownButton
(String id, Icon icon, String text, StyleElement... styles) Creates a button with the specified icon, text and style(s).DropDownButton
(String id, String text) Creates a button with the specified text -
Method Summary
Modifier and TypeMethodDescriptionAdds an animation end event handler to the component.Adds an animation start event handler to the component.addClickHandler
(ClickEventHandler handler) Adds a click event handler to the button.addComponent
(Component<?> component) Adds a component to the dropdown menu.final DropDownButton
Adds a divider to the button drop down menu.Adds a double click event handler to the button.Adds a header to the dropdown menu.addHotKey
(int hotKey) Adds the specified hot key to the component.addHotKey
(int hotKey, HotKeyEventHandler handler) Adds the specified hot key to the component.addMenuItem
(Icon icon, String text, int hotKey, ClickEventHandler clickHandler) Adds a menu item with the specified icon, text, hot key and click handler to the button's drop down menufinal DropDownButton
addMenuItem
(Icon icon, String text, ClickEventHandler handler) Adds a menu item with the specified icon, text and click handler to the button's drop down menuaddMouseDownHandler
(MouseDownEventHandler handler) Adds a mouse button down event handler to the component.Adds a mouse enter event handler to the component.Adds a mouse leave event handler to the component.addMouseMoveHandler
(MouseMoveEventHandler handler) Adds a mouse move event handler to the component.addMouseOutHandler
(MouseOutEventHandler handler) Adds a mouse out event handler to the component.addMouseOverHandler
(MouseOverEventHandler handler) Adds a mouse over event handler to the component.addMouseUpHandler
(MouseUpEventHandler handler) Adds a mouse up event handler to the component.Adds a mouse wheel event handler to the component.Adds a touch cancel event handler to the component.addTouchEndHandler
(TouchEndEventHandler handler) Adds a touch end event handler to the component.addTouchMoveHandler
(TouchMoveEventHandler handler) Adds a touch move event handler.Adds a touch start event handler to the component.final DropDownButton
clear()
Removes all components, headers, borders and menu items from the dropdown menu.Gets the component's animation typefinal long
Gets the counter valueGets the dropdown direction.getIcon()
Gets the button icongetItem
(int index) Gets a menu item by referencing its index.Gets the dropdown menu alignment.getText()
Gets the button textvoid
init()
The component initialization method.Removes animation from the componentremoveHotKey
(int hotKey) Removes the specified hot key from the componentRemoves every hot key from the componentsetAnimation
(Animation animation) Sets the animation type on the componentfinal DropDownButton
setCounter
(long value) Adds a counter to the right side of the button.setDirection
(DropDownDirection direction) Sets the dropdown direction.Sets the button iconPlaces an image on the buttonDropdown menu alignment relative to the button.setMenuOffset
(int offsetX, int offsetY) Sets the X and Y axis offset of the dropdown menu.setSize
(ButtonSize size) Stets the button sizeSets the button textsetType
(ButtonType type) Sets the button sizeboolean
writeHTML
(StringWriter writer) Creates the component's HTML equivalentMethods inherited from class com.jbstrap.ui.Component
_hide, _setAttribute, addAllowedRole, addComponent, addComponents, addDeniedRole, addHandler, addStyle, addStyleClass, addStyleClasses, afterDraw, clearfix, closeTag, combinateAccess, containsStyle, containsStyleClass, draw, drawSubComponents, error, flattendComponentTree, getAccess, getAccessMode, getAllowedRoles, getAttribute, getAttributes, getBackgroundColor, getBorderColor, getClient, getComponentById, getComponents, getComponents, getComponentsByClass, getData, getDeniedRoles, getHandlers, getId, getLanguageCode, getName, getParent, getParent, getRegisteredEvents, getStyle, getStyleClasses, getTextAlign, getTextColor, getToolTip, getToolTipPosition, getTypeName, getUI, insertComponentAfter, insertComponentBefore, isAccess, isDrawn, isEnabled, isEventBubbling, isVisible, onHide, onHotKeyEventHandler, onShow, openTag, redraw, removeAllComponents, removeAllowedRole, removeAllStyleClasses, removeAttribute, removeComponent, removeComponent, removeComponents, removeDeniedRole, removeHandler, removeStyle, removeStyle, removeStyleClass, removeStyleClasses, replaceComponent, replaceStyleClass, runAfterDraw, runJavaScript, runJavaScript, runJavaScript, runOnHide, runOnShow, say, setAttribute, setBackgroundColor, setBorder, setBorderColor, setData, setDisplayType, setEnabled, setEventBubbling, setFlex, setFloating, setHeight100, setHeight25, setHeight50, setHeight75, setHeightAuto, setLanguage, setMargin, setName, setOverflow, setPadding, setParent, setScrollable, setSelectionType, setShadow, setStyle, setTextAlign, setTextColor, setToolTip, setToolTipPosition, setVisible, setWidth100, setWidth25, setWidth50, setWidth75, setWidthAuto, showNotification, showNotification, showProcessIndicator, toggleStyleClass
Methods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.ui.CanDrop
addDropEventHandler
Methods inherited from interface com.jbstrap.ui.Draggable
addDragEndEventHandler, addDragStartEventHandler, setDraggable
-
Constructor Details
-
DropDownButton
creates a button with the specified icon- Parameters:
icon
- the icon of the button. for the applicable icons, see theIcon
enum.- Throws:
illegalstateexception
- if the component is set to be both private and public, through an annotation.
-
DropDownButton
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 theIcon
enum.- Throws:
IllegalStateException
- If the component is set to be both Private and Public, through an annotation.
-
DropDownButton
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.
-
DropDownButton
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.
-
DropDownButton
Creates a button with the specified icon and text- Parameters:
icon
- The icon of the button. For the applicable icons, see theIcon
enum.text
- The button text- Throws:
IllegalStateException
- If the component is set to be both Private and Public, through an annotation.
-
DropDownButton
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 theIcon
enum.text
- The button text- Throws:
IllegalStateException
- If the component is set to be both Private and Public, through an annotation.
-
DropDownButton
Creates a button with the specified text and style(s).- Parameters:
text
- The button textstyles
- The style (type and/or size) of the button. For the applicable types, see theButtonType
enum. For the applicable sizes, see theButtonSize
enum.- Throws:
IllegalStateException
- If the component is set to be both Private and Public, through an annotation.
-
DropDownButton
Creates a button with the specified icon, text and style(s).- Parameters:
icon
- The icon of the button. For the applicable icons, see theIcon
enum.text
- The button textstyles
- The style (type and/or size) of the button. For the applicable types, see theButtonType
enum. For the applicable sizes, see theButtonSize
enum.- Throws:
IllegalStateException
- If the component is set to be both Private and Public, through an annotation.
-
DropDownButton
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 theIcon
enum.text
- The button textstyles
- The style (type and/or size) of the button. For the applicable types, see theButtonType
enum. For the applicable sizes, see theButtonSize
enum.- Throws:
IllegalStateException
- If the component is set to be both Private and Public, through an annotation.
-
-
Method Details
-
init
Description copied from class:Component
The component initialization method.Empty method, only needs to be overwritten when making a custom component, that needs to call an initializing JavaScript on the client side. The method is called by the framework after the component is drawn, but before the afterDraw() method. The use of this method during application development is not allowed. This method is meant for inner use only.
- Overrides:
init
in classComponent<DropDownButton>
- Throws:
JavaScriptLoadError
- If there was a JavaScript error during the initialization.
-
setText
Sets the button text- Parameters:
text
- The button text- Returns:
- The button component
-
getText
Gets the button text- Returns:
- The current button text. If it has no text, returns with
null
-
setIcon
Sets the button icon- Parameters:
icon
- The icon of the button. For the applicable icons, see theIcon
enum.- Returns:
- The button component
-
getIcon
Gets the button icon- Returns:
- The current button icon. If it has no icon, returns with
null
-
setImage
Places an image on the button- Parameters:
image
- The image that will be on the button. If specified asnull
, nothing will be placed.- Returns:
- The button component
-
setType
Sets the button size- Parameters:
type
- The size of the button. For the applicable types, see theButtonType
enum.- Returns:
- The button
-
setSize
Stets the button size- Parameters:
size
- The style size of the button. For the applicable types, see theButtonSize
enum.- Returns:
- The button
-
setCounter
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.
-
setDirection
Sets the dropdown direction. By default, a dropdown menu opens downwards, but you can use this method to modify it upwards or left/right.- Parameters:
direction
- Dropdown direction Ifnull
is specified, the dropdown menu opens downwards. Available directions are listed in the enumDropDownDirection
- Returns:
- Button component
-
getDirection
Gets the dropdown direction.- Returns:
- Dropdown direction
-
addMenuItem
Adds a menu item with the specified icon, text and click handler to the button's drop down menu- Parameters:
icon
- The icon of the button. For the applicable icons, see theIcon
enum.text
- The button texthandler
- The click even handler implementation- Returns:
- The button component
-
addMenuItem
public DropDownButton addMenuItem(Icon icon, String text, int hotKey, ClickEventHandler clickHandler) Adds a menu item with the specified icon, text, hot key and click handler to the button's drop down menu- Parameters:
icon
- The icon of the button. For the applicable icons, see theIcon
enum.text
- The button texthotKey
- The menu hot key. This can be specified by using one of the Key class' constants. For example, adding CTRL+S:Key.CRTL + Key.KEY_S
clickHandler
- The click even handler implementation- Returns:
- The button component
-
addDivider
Adds a divider to the button drop down menu.- Returns:
- The button component
-
addHeader
Adds a header to the dropdown menu. Users cannot click on a header, it is only displayed as an information box.- Parameters:
text
- Header text- Returns:
- Button component
-
addComponent
Adds a component to the dropdown menu.- Overrides:
addComponent
in classComponent<DropDownButton>
- Parameters:
component
- The component to be added- Returns:
- The component
-
getItem
Gets a menu item by referencing its index.- Parameters:
index
- Menu item index- Returns:
- Menu item component or
null
, if there is no menu item with the specified index
-
setAnimation
Description copied from interface:Animatable
Sets the animation type on the component- Specified by:
setAnimation
in interfaceAnimatable<DropDownButton>
- Parameters:
animation
- The animation type. The usable animation types can be found in theAnimation
enum- Returns:
- The component
-
getAnimation
Description copied from interface:Animatable
Gets the component's animation type- Specified by:
getAnimation
in interfaceAnimatable<DropDownButton>
- Returns:
- The animation type that is assigned to the component
-
removeAnimation
Description copied from interface:Animatable
Removes animation from the component- Specified by:
removeAnimation
in interfaceAnimatable<DropDownButton>
- Returns:
- The component
-
addAnimationStartHandler
Description copied from interface:Animatable
Adds an animation start event handler to the component. This handler is used, when the animation has starts.- Specified by:
addAnimationStartHandler
in interfaceAnimatable<DropDownButton>
- Parameters:
handler
- TheAnimationStartEventHandler
implementation- Returns:
- The component
- See Also:
-
addAnimationEndHandler
Description copied from interface:Animatable
Adds an animation end event handler to the component. This handler is used, when the animation has ended.- Specified by:
addAnimationEndHandler
in interfaceAnimatable<DropDownButton>
- Parameters:
handler
- TheAnimationEndEventHandler
implementation- Returns:
- The component
- See Also:
-
addClickHandler
Adds a click event handler to the button.
If you add a click event handler to the dropdown menu item, the menu opens only by clicking on the dropdown icon. If you click on the button, only the specified event handler runs.
- Specified by:
addClickHandler
in interfaceClickable<DropDownButton>
- Parameters:
handler
- TheClickEventHandler
implementation- Returns:
- The component
- See Also:
-
addDoubleClickHandler
Adds a double click event handler to the button.
If you add a click event handler to the dropdown menu item, the menu opens only by clicking on the dropdown icon. If you click on the button, only the specified event handler runs.
- Specified by:
addDoubleClickHandler
in interfaceClickable<DropDownButton>
- Parameters:
handler
- ADoubleClickEventHandler
implementation- Returns:
- The component
- See Also:
-
addHotKey
Description copied from interface:HandleHotKey
Adds the specified hot key to the component. If the user presses the hot key, the component's Click event handler will be fired. If the hot key was assigned to an input field, the field will gain focus.- Specified by:
addHotKey
in interfaceHandleHotKey<DropDownButton>
- Parameters:
hotKey
- The button combination, that will be assigned to the component. This button combination can be specified, by using theKey
class' constants. If the hot key is a combination of two buttons, then the values must be added. For example, the CTRL+S combination is specified asKEY.CTRL + KEY.KEY_S
- Returns:
- The component
-
addHotKey
Description copied from interface:HandleHotKey
Adds the specified hot key to the component. If the user presses the hot key, the specified event handler will be fired- Specified by:
addHotKey
in interfaceHandleHotKey<DropDownButton>
- Parameters:
hotKey
- The button combination, that will be assigned to the component. This button combination can be specified, by using theKey
class' constants. If the hot key is a combination of two buttons, then the values must be added. For example, the CTRL+S combination is specified asKEY.CTRL + KEY.KEY_S
handler
- TheHotKeyEventHandler
implementation- Returns:
- The component
- See Also:
-
removeHotKey
Description copied from interface:HandleHotKey
Removes the specified hot key from the component- Specified by:
removeHotKey
in interfaceHandleHotKey<DropDownButton>
- Parameters:
hotKey
- The button combination assigned to the component. This button combination can be specified, by using theKey
class' constants. If the hot key is a combination of two buttons, then the values must be added. For example, the CTRL+S combination is specified asKEY.CTRL + KEY.KEY_S
- Returns:
- The component
-
removeHotKeys
Description copied from interface:HandleHotKey
Removes every hot key from the component- Specified by:
removeHotKeys
in interfaceHandleHotKey<DropDownButton>
- Returns:
- The component
-
addMouseDownHandler
Description copied from interface:HandleMouseEvents
Adds a mouse button down event handler to the component. The handler will run when the user presses a mouse button while having the mouse in the component- Specified by:
addMouseDownHandler
in interfaceHandleMouseEvents<DropDownButton>
- Parameters:
handler
- TheMouseDownEventHandler
implementation- Returns:
- The component
- See Also:
-
addMouseEnterHandler
Description copied from interface:HandleMouseEvents
Adds a mouse enter event handler to the component. The handler will run when the mouse cursor enters the component, i.e. when the user hovers with the mouse over the component.- Specified by:
addMouseEnterHandler
in interfaceHandleMouseEvents<DropDownButton>
- Parameters:
handler
- TheMouseEnterEventHandler
implementation- Returns:
- The component
- See Also:
-
addMouseLeaveHandler
Description copied from interface:HandleMouseEvents
Adds a mouse leave event handler to the component. The handler will run when the mouse cursor leaves the component.- Specified by:
addMouseLeaveHandler
in interfaceHandleMouseEvents<DropDownButton>
- Parameters:
handler
- TheMouseLeaveEventHandler
implementation- Returns:
- The component
- See Also:
-
addMouseMoveHandler
Description copied from interface:HandleMouseEvents
Adds a mouse move event handler to the component. The handler will run when the mouse cursor moves inside the component area.- Specified by:
addMouseMoveHandler
in interfaceHandleMouseEvents<DropDownButton>
- Parameters:
handler
- TheMouseMoveEventHandler
implementation- Returns:
- The component
- See Also:
-
addMouseOutHandler
Description copied from interface:HandleMouseEvents
Adds a mouse out event handler to the component. The handler will run when the mouse cursor moves out of a component- Specified by:
addMouseOutHandler
in interfaceHandleMouseEvents<DropDownButton>
- Parameters:
handler
- TheMouseOutEventHandler
implementation- Returns:
- The component
- See Also:
-
addMouseOverHandler
Description copied from interface:HandleMouseEvents
Adds a mouse over event handler to the component. The handler will run when the mouse cursor moves over a component- Specified by:
addMouseOverHandler
in interfaceHandleMouseEvents<DropDownButton>
- Parameters:
handler
- TheMouseOverEventHandler
implementation- Returns:
- The component
- See Also:
-
addMouseUpHandler
Description copied from interface:HandleMouseEvents
Adds a mouse up event handler to the component. The handler will run when the mouse button is released, while the cursor is in a component.- Specified by:
addMouseUpHandler
in interfaceHandleMouseEvents<DropDownButton>
- Parameters:
handler
- TheMouseUpEventHandler
implementation- Returns:
- The component
- See Also:
-
addMouseWheelHandler
Description copied from interface:HandleMouseEvents
Adds a mouse wheel event handler to the component. The handler will run when the mouse wheel is used (scrolling), while the cursor is in a component- Specified by:
addMouseWheelHandler
in interfaceHandleMouseEvents<DropDownButton>
- Parameters:
handler
- TheMouseWheelEventHandler
implementation- Returns:
- The component
- See Also:
-
addTouchCancelHandler
Description copied from interface:Touchable
Adds a touch cancel event handler to the component. The event is fired when the touch event is cancelled by the device. Each device cancels the touch event differently, and certain devices use this event. If the device fires the event, the event handler will also be called.- Specified by:
addTouchCancelHandler
in interfaceTouchable<DropDownButton>
- Parameters:
handler
- TheTouchCancelEventHandler
implementation- Returns:
- The component
- See Also:
-
addTouchEndHandler
Description copied from interface:Touchable
Adds a touch end event handler to the component. The specified handler will be used, when the user takes their finger off the component.- Specified by:
addTouchEndHandler
in interfaceTouchable<DropDownButton>
- Parameters:
handler
- TheTouchEndEventHandler
implementation- Returns:
- The component
- See Also:
-
addTouchMoveHandler
Description copied from interface:Touchable
Adds a touch move event handler. The handler will be used, when the user moves their finger on the screen.- Specified by:
addTouchMoveHandler
in interfaceTouchable<DropDownButton>
- Parameters:
handler
- TheTouchMoveEventHandler
implementation- Returns:
- The component
- See Also:
-
addTouchStartHandler
Description copied from interface:Touchable
Adds a touch start event handler to the component. The handler will be used, when the user touches component.- Specified by:
addTouchStartHandler
in interfaceTouchable<DropDownButton>
- Parameters:
handler
- TheTouchStartEventHandler
implementation- Returns:
- The component
- See Also:
-
setMenuOffset
Sets the X and Y axis offset of the dropdown menu.- Parameters:
offsetX
- X axis offset in pixelsoffsetY
- Y axis offset in pixels- Returns:
- Button component
-
setMenuAlignament
Dropdown menu alignment relative to the button. By default, the dropdown menu is displayed to the left from the button.- Parameters:
align
- Dropdown menu alignment Ifnull
is specified, the menu opens on the left side of the button. Available alignment types are listed in the enumDropDownAlignament
- Returns:
- Button component
-
getMenuAlignament
Gets the dropdown menu alignment.- Returns:
- Dropdown menu alignment
-
clear
Removes all components, headers, borders and menu items from the dropdown menu. -
writeHTML
Description copied from class:Component
Creates the component's HTML equivalentThis 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 withfalse
. Otherwise, it must return withtrue
.- Specified by:
writeHTML
in classComponent<DropDownButton>
- Returns:
- If the componentwas drawn,
true
, otherwisefalse
-