Class FloatingActionButton
- All Implemented Interfaces:
Animation, Editable, ActionSource<ActionEvent>, StyleListener, IconHolder, ReleasableComponent, SelectableIconHolder, TextHolder
Floating action buttons are a material design element used to promote a special action in a Form. They are represented as a floating circle with a flat icon floating above the UI typically in the bottom right area.
Simple use cases include just the button as a standalone:
FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_ADD);
fab.addActionListener(e -> ToastBar.showErrorMessage("Not implemented yet..."));
fab.bindFabToContainer(hi.getContentPane());
The button can also nest sub actions
FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_ADD);
fab.createSubFAB(FontImage.MATERIAL_PEOPLE, "");
fab.createSubFAB(FontImage.MATERIAL_IMPORT_CONTACTS, "");
fab.bindFabToContainer(hi.getContentPane());
-
Field Summary
Fields inherited from class Button
STATE_DEFAULT, STATE_PRESSED, STATE_ROLLOVERFields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFloatingActionButton(char icon, String text, float size) ConstructorprotectedFloatingActionButton(char icon, String text, String uiid, float size) Constructor -
Method Summary
Modifier and TypeMethodDescriptionThis is a utility method to bind the FAB to a given Container, it will return a new container to add or will use the layered pane if the container is a content pane.bindFabToContainer(Component cnt, int orientation, int valign) This is a utility method to bind the FAB to a given Container, it will return a new container to add or will use the layered pane if the container is a content pane.protected DimensionCalculates the preferred size based on component content.static FloatingActionButtoncreateBadge(String text) Creates a text badgestatic FloatingActionButtoncreateFAB(char icon) a factory method to create a FloatingActionButton.static FloatingActionButtona factory method to create a FloatingActionButton.protected ContainerCreates the popup content container to display on the dialog.createSubFAB(char icon, String text) Adds a sub FAB to the FloatingActionButton instance.protected voidfireActionEvent(int x, int y) Allows subclasses to override action event behavior
Allows subclasses to override action event behavior
Parameters
-
x: the x position of the click if applicable (can be 0 or -1 otherwise) -
y: the y position of the click if applicable (can be 0 or -1 otherwise)
Returns
static floatThe default icon size for the fab icon in millimetersstatic booleanThe FloatingActionButton tries to size/pad itself automatically but this means that manual padding is ignored.voidreleased(int x, int y) Invoked to change the state of the button to the released statestatic voidsetAutoSizing(boolean aAutoSizing) The FloatingActionButton tries to size/pad itself automatically but this means that manual padding is ignored.voidsetFloatingActionTextUIID(String floatingActionTextUIID) Parameters
static voidsetIconDefaultSize(float aFabDefaultSize) The default icon size for the fab icon in millimetersvoidOverriden to implement the caps mode#setCapsText(boolean)Overriden to implement the caps mode#setCapsText(boolean)Sets the Label textvoidOverriden to update the icon Overriden to workaround issue with caps text and different UIID's This method sets the Component the Unique identifier.protected voidshowPopupDialog(Dialog dialog) Shows the popup Dialog with the sub FABs.voidstyleChanged(String propertyName, Style source) We override this method to track style changes to the background color and map them to the bordervoidunbind()Removes the floating action button from its parentMethods inherited from class Button
addActionListener, addStateChangeListener, animate, bindStateTo, dragInitiated, fireClicked, getActionListeners, getBorder, getCommand, getDisabledIcon, getIconFromState, getListeners, getPressedIcon, getReleaseRadius, getRolloverIcon, getRolloverPressedIcon, getState, isAutoRelease, isButtonRippleEffectDefault, isCapsText, isCapsTextDefault, isOppositeSide, isSelectableInteraction, isSelected, isToggle, keyPressed, keyReleased, keyRepeated, paint, pointerHover, pointerHoverReleased, pointerPressed, pointerReleased, pressed, released, removeActionListener, removeStateChangeListener, resetFocusable, setAlignment, setAutoRelease, setButtonRippleEffectDefault, setCapsText, setCapsTextDefault, setCommand, setDisabledIcon, setPressedIcon, setReleased, setReleaseRadius, setRolloverIcon, setRolloverPressedIcon, setToggle, unbindStateFromMethods inherited from class Label
bindProperty, getAlignment, getBadgeStyleComponent, getBadgeText, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBoundPropertyValue, getDefaultGap, getFontIcon, getFontIconSize, getGap, getIcon, getIconFont, getIconStyleComponent, getIconUIID, getMask, getMaskedIcon, getMaskName, getMaterialIcon, getMaterialIconSize, getMaxAutoSize, getMinAutoSize, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getShiftMillimeters, getShiftMillimetersF, getShiftText, getStringWidth, getText, getTextPosition, getTextSelectionSupport, getVerticalAlignment, initLaf, initUnselectedStyle, isAutoSizeMode, isDefaultTickerEnabled, isEndsWith3Points, isLegacyRenderer, isShouldLocalize, isShowEvenIfBlank, isTextSelectionEnabled, isTickerEnabled, isTickerRunning, laidOut, paramString, refreshTheme, setAutoSizeMode, setBadgeText, setBadgeUIID, setBoundPropertyValue, setDefaultGap, setDefaultTickerEnabled, setEndsWith3Points, setFontIcon, setFontIcon, setFontIcon, setGap, setIcon, setIconUIID, setLegacyRenderer, setMask, setMaskName, setMaterialIcon, setMaterialIcon, setMaxAutoSize, setMinAutoSize, setPropertyValue, setShiftMillimeters, setShiftMillimeters, setShiftText, setShouldLocalize, setShowEvenIfBlank, setTextPosition, setTextSelectionEnabled, setTickerEnabled, setVerticalAlignment, shouldTickerStart, startTicker, startTicker, stopTicker, unbindPropertyMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, announceForAccessibility, blocksSideSwipe, calcScrollSize, cancelRepaints, clearClientProperties, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, drop, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBottomGap, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSideGap, getStyle, getTabIndex, getTensileLength, getTooltip, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHoverPressed, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, repaint, repaint, requestFocus, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIIDFinal, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, toImage, toString, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface IconHolder
getGap, getIcon, getIconStyleComponent, getIconUIID, getTextPosition, setFontIcon, setGap, setIcon, setIconUIID, setMaterialIcon, setTextPosition -
-
Constructor Details
-
FloatingActionButton
Constructor
Parameters
-
icon: one of the FontImage.MATERIAL_* constants -
text: the text of the sub FloatingActionButton -
size: the size in millimeters
-
-
FloatingActionButton
-
-
Method Details
-
getIconDefaultSize
public static float getIconDefaultSize()The default icon size for the fab icon in millimeters
Returns
the fabDefaultSize
-
setIconDefaultSize
public static void setIconDefaultSize(float aFabDefaultSize) The default icon size for the fab icon in millimeters
Parameters
aFabDefaultSize: the fabDefaultSize to set
-
isAutoSizing
public static boolean isAutoSizing()The FloatingActionButton tries to size/pad itself automatically but this means that manual padding is ignored. Setting this to false disables that behavior
Returns
the autoSizing
-
setAutoSizing
public static void setAutoSizing(boolean aAutoSizing) The FloatingActionButton tries to size/pad itself automatically but this means that manual padding is ignored. Setting this to false disables that behavior
Parameters
aAutoSizing: the autoSizing to set
-
createBadge
Creates a text badge
Parameters
text: the text of the badge
Returns
a badge component
-
createFAB
a factory method to create a FloatingActionButton.
Parameters
icon: one of the FontImage.MATERIAL_* constants
Returns
a FloatingActionButton instance
-
createFAB
a factory method to create a FloatingActionButton.
Parameters
-
icon: one of the FontImage.MATERIAL_* constants -
uiid: the uiid for the fab
Returns
a FloatingActionButton instance
-
-
setUIID
Overriden to update the icon
Overriden to workaround issue with caps text and different UIID's
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
-
styleChanged
We override this method to track style changes to the background color and map them to the border
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 callingCN.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:
styleChangedin interfaceStyleListener- Overrides:
styleChangedin classLabel
-
-
createSubFAB
Adds a sub FAB to the FloatingActionButton instance. Once pressed all its sub FAB's are displayed.
Parameters
-
icon: one of the FontImage.MATERIAL_* constants -
text: the text of the sub FloatingActionButton
Returns
a FloatingActionButton instance for the sub FAB added
-
-
calcPreferredSize
Description copied from class:ButtonCalculates the preferred size based on component content. This method is invoked lazily by getPreferred size.
Returns
the calculated preferred size based on component content
- Overrides:
calcPreferredSizein classButton
-
bindFabToContainer
This is a utility method to bind the FAB to a given Container, it will return a new container to add or will use the layered pane if the container is a content pane.
Parameters
cnt: the Container to add the FAB to
Returns
a new Container that contains the cnt and the FAB on top or null in the case of a content pane
-
bindFabToContainer
This is a utility method to bind the FAB to a given Container, it will return a new container to add or will use the layered pane if the container is a content pane.
Parameters
-
cnt: the Container to add the FAB to -
orientation: one of Component.RIGHT/LEFT/CENTER -
valign: one of Component.TOP/BOTTOM/CENTER
Returns
a new Container that contains the cnt and the FAB on top or null in the case of a content pane
-
-
unbind
public void unbind()Removes the floating action button from its parent -
setText
-
fireActionEvent
protected void fireActionEvent(int x, int y) Description copied from class:ButtonAllows subclasses to override action event behavior
Parameters
-
x: the x position of the click if applicable (can be 0 or -1 otherwise) -
y: the y position of the click if applicable (can be 0 or -1 otherwise)
- Overrides:
fireActionEventin classButton
-
-
released
public void released(int x, int y) Description copied from class:ButtonInvoked to change the state of the button to the released state
Parameters
-
x: the x position if a touch event triggered this, -1 if this isn't relevant -
y: the y position if a touch event triggered this, -1 if this isn't relevant
-
-
createPopupContent
Creates the popup content container to display on the dialog.
Parameters
fabs: List of sub FloatingActionButton
Returns
a Container that contains all fabs
-
showPopupDialog
Shows the popup Dialog with the sub FABs.
Parameters
dialog: the Dialog with all sub FAB's Components
-
getFloatingActionTextUIID
Returns
the floatingActionTextUIID
-
setFloatingActionTextUIID
Parameters
floatingActionTextUIID: the floatingActionTextUIID to set
-