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
Nested Classes -
Field Summary
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition -
Constructor Summary
ConstructorsConstructorDescriptionDropDownButton(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 DropDownButtonAdds 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 DropDownButtonaddMenuItem(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 DropDownButtonclear()Removes all components, headers, borders and menu items from the dropdown menu.Gets the component's animation typefinal longGets 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 textvoidinit()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 DropDownButtonsetCounter(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 sizebooleanwriteHTML(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, toggleStyleClassMethods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBusMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.jbstrap.ui.CanDrop
addDropEventHandlerMethods 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 theIconenum.- 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 theIconenum.- 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 theIconenum.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 theIconenum.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 theButtonTypeenum. For the applicable sizes, see theButtonSizeenum.- 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 theIconenum.text- The button textstyles- The style (type and/or size) of the button. For the applicable types, see theButtonTypeenum. For the applicable sizes, see theButtonSizeenum.- 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 theIconenum.text- The button textstyles- The style (type and/or size) of the button. For the applicable types, see theButtonTypeenum. For the applicable sizes, see theButtonSizeenum.- Throws:
IllegalStateException- If the component is set to be both Private and Public, through an annotation.
-
-
Method Details
-
init
Description copied from class:ComponentThe 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:
initin 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 theIconenum.- 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 theButtonTypeenum.- Returns:
- The button
-
setSize
Stets the button size- Parameters:
size- The style size of the button. For the applicable types, see theButtonSizeenum.- 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 Ifnullis 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 theIconenum.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 theIconenum.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_SclickHandler- 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:
addComponentin 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:AnimatableSets the animation type on the component- Specified by:
setAnimationin interfaceAnimatable<DropDownButton>- Parameters:
animation- The animation type. The usable animation types can be found in theAnimationenum- Returns:
- The component
-
getAnimation
Description copied from interface:AnimatableGets the component's animation type- Specified by:
getAnimationin interfaceAnimatable<DropDownButton>- Returns:
- The animation type that is assigned to the component
-
removeAnimation
Description copied from interface:AnimatableRemoves animation from the component- Specified by:
removeAnimationin interfaceAnimatable<DropDownButton>- Returns:
- The component
-
addAnimationStartHandler
Description copied from interface:AnimatableAdds an animation start event handler to the component. This handler is used, when the animation has starts.- Specified by:
addAnimationStartHandlerin interfaceAnimatable<DropDownButton>- Parameters:
handler- TheAnimationStartEventHandlerimplementation- Returns:
- The component
- See Also:
-
addAnimationEndHandler
Description copied from interface:AnimatableAdds an animation end event handler to the component. This handler is used, when the animation has ended.- Specified by:
addAnimationEndHandlerin interfaceAnimatable<DropDownButton>- Parameters:
handler- TheAnimationEndEventHandlerimplementation- 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:
addClickHandlerin interfaceClickable<DropDownButton>- Parameters:
handler- TheClickEventHandlerimplementation- 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:
addDoubleClickHandlerin interfaceClickable<DropDownButton>- Parameters:
handler- ADoubleClickEventHandlerimplementation- Returns:
- The component
- See Also:
-
addHotKey
Description copied from interface:HandleHotKeyAdds 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:
addHotKeyin interfaceHandleHotKey<DropDownButton>- Parameters:
hotKey- The button combination, that will be assigned to the component. This button combination can be specified, by using theKeyclass' 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:HandleHotKeyAdds the specified hot key to the component. If the user presses the hot key, the specified event handler will be fired- Specified by:
addHotKeyin interfaceHandleHotKey<DropDownButton>- Parameters:
hotKey- The button combination, that will be assigned to the component. This button combination can be specified, by using theKeyclass' 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_Shandler- TheHotKeyEventHandlerimplementation- Returns:
- The component
- See Also:
-
removeHotKey
Description copied from interface:HandleHotKeyRemoves the specified hot key from the component- Specified by:
removeHotKeyin interfaceHandleHotKey<DropDownButton>- Parameters:
hotKey- The button combination assigned to the component. This button combination can be specified, by using theKeyclass' 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:HandleHotKeyRemoves every hot key from the component- Specified by:
removeHotKeysin interfaceHandleHotKey<DropDownButton>- Returns:
- The component
-
addMouseDownHandler
Description copied from interface:HandleMouseEventsAdds 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:
addMouseDownHandlerin interfaceHandleMouseEvents<DropDownButton>- Parameters:
handler- TheMouseDownEventHandlerimplementation- Returns:
- The component
- See Also:
-
addMouseEnterHandler
Description copied from interface:HandleMouseEventsAdds 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:
addMouseEnterHandlerin interfaceHandleMouseEvents<DropDownButton>- Parameters:
handler- TheMouseEnterEventHandlerimplementation- Returns:
- The component
- See Also:
-
addMouseLeaveHandler
Description copied from interface:HandleMouseEventsAdds a mouse leave event handler to the component. The handler will run when the mouse cursor leaves the component.- Specified by:
addMouseLeaveHandlerin interfaceHandleMouseEvents<DropDownButton>- Parameters:
handler- TheMouseLeaveEventHandlerimplementation- Returns:
- The component
- See Also:
-
addMouseMoveHandler
Description copied from interface:HandleMouseEventsAdds a mouse move event handler to the component. The handler will run when the mouse cursor moves inside the component area.- Specified by:
addMouseMoveHandlerin interfaceHandleMouseEvents<DropDownButton>- Parameters:
handler- TheMouseMoveEventHandlerimplementation- Returns:
- The component
- See Also:
-
addMouseOutHandler
Description copied from interface:HandleMouseEventsAdds a mouse out event handler to the component. The handler will run when the mouse cursor moves out of a component- Specified by:
addMouseOutHandlerin interfaceHandleMouseEvents<DropDownButton>- Parameters:
handler- TheMouseOutEventHandlerimplementation- Returns:
- The component
- See Also:
-
addMouseOverHandler
Description copied from interface:HandleMouseEventsAdds a mouse over event handler to the component. The handler will run when the mouse cursor moves over a component- Specified by:
addMouseOverHandlerin interfaceHandleMouseEvents<DropDownButton>- Parameters:
handler- TheMouseOverEventHandlerimplementation- Returns:
- The component
- See Also:
-
addMouseUpHandler
Description copied from interface:HandleMouseEventsAdds 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:
addMouseUpHandlerin interfaceHandleMouseEvents<DropDownButton>- Parameters:
handler- TheMouseUpEventHandlerimplementation- Returns:
- The component
- See Also:
-
addMouseWheelHandler
Description copied from interface:HandleMouseEventsAdds 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:
addMouseWheelHandlerin interfaceHandleMouseEvents<DropDownButton>- Parameters:
handler- TheMouseWheelEventHandlerimplementation- Returns:
- The component
- See Also:
-
addTouchCancelHandler
Description copied from interface:TouchableAdds 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:
addTouchCancelHandlerin interfaceTouchable<DropDownButton>- Parameters:
handler- TheTouchCancelEventHandlerimplementation- Returns:
- The component
- See Also:
-
addTouchEndHandler
Description copied from interface:TouchableAdds 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:
addTouchEndHandlerin interfaceTouchable<DropDownButton>- Parameters:
handler- TheTouchEndEventHandlerimplementation- Returns:
- The component
- See Also:
-
addTouchMoveHandler
Description copied from interface:TouchableAdds a touch move event handler. The handler will be used, when the user moves their finger on the screen.- Specified by:
addTouchMoveHandlerin interfaceTouchable<DropDownButton>- Parameters:
handler- TheTouchMoveEventHandlerimplementation- Returns:
- The component
- See Also:
-
addTouchStartHandler
Description copied from interface:TouchableAdds a touch start event handler to the component. The handler will be used, when the user touches component.- Specified by:
addTouchStartHandlerin interfaceTouchable<DropDownButton>- Parameters:
handler- TheTouchStartEventHandlerimplementation- 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 Ifnullis 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:ComponentCreates 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 (
StringWriterclass) 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:
writeHTMLin classComponent<DropDownButton>- Returns:
- If the componentwas drawn,
true, otherwisefalse
-