public class FloatingActionButton

  1. Object
  2. Component
  3. Label
  4. Button
  5. FloatingActionButton

ImplementsActionSource<ActionEvent>, Animation, Editable, IconHolder, ReleasableComponent, SelectableIconHolder, StyleListener, 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());

Constructors

protected FloatingActionButton(char icon, String text, float size)Constructor
protected FloatingActionButton(char icon, String text, String uiid, float size)Constructor

Methods

public static float getIconDefaultSize()The default icon size for the fab icon in millimeters
public static void setIconDefaultSize(float aFabDefaultSize)The default icon size for the fab icon in millimeters
public static boolean isAutoSizing()The FloatingActionButton tries to size/pad itself automatically but this means that manual padding is ignored.
public static void setAutoSizing(boolean aAutoSizing)The FloatingActionButton tries to size/pad itself automatically but this means that manual padding is ignored.
public static FloatingActionButton createBadge(String text)Creates a text badge
public static FloatingActionButton createFAB(char icon)a factory method to create a FloatingActionButton.
public static FloatingActionButton createFAB(char icon, String uiid)a factory method to create a FloatingActionButton.
public void setUIID(String id)Overriden to update the icon Overriden to workaround issue with caps text and different UIID’s This method sets the Component the Unique identifier.
public void styleChanged(String propertyName, Style source)We override this method to track style changes to the background color and map them to the border
public FloatingActionButton createSubFAB(char icon, String text)Adds a sub FAB to the FloatingActionButton instance.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public Container bindFabToContainer(Component cnt)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.
public Container 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.
public void unbind()Removes the floating action button from its parent
public void setText(String text)Overriden to implement the caps mode #setCapsText(boolean) Sets the Label text
protected void fireActionEvent(int x, int y)Allows subclasses to override action event behavior for pointer coordinates.
public void released(int x, int y)Invoked to change the state of the button to the released state
protected Container createPopupContent(List<FloatingActionButton> fabs)Creates the popup content container to display on the dialog.
protected void showPopupDialog(Dialog dialog)Shows the popup Dialog with the sub FABs.
public String getFloatingActionTextUIID()
public void setFloatingActionTextUIID(String floatingActionTextUIID)

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, stopScrollMomentum, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, deinitialize, initComponent, isInitialized, setInitialized, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

FloatingActionButton

protected FloatingActionButton(char icon, String text, float size)
Constructor

Parameters

icon char
one of the FontImage.MATERIAL_* constants
text String
the text of the sub FloatingActionButton
size float
the size in millimeters

FloatingActionButton

protected FloatingActionButton(char icon, String text, String uiid, float size)
Constructor

Parameters

icon char
one of the FontImage.MATERIAL_* constants
text String
the text of the sub FloatingActionButton
uiid String
the uiid of the FAB
size float
the size in millimeters

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 float
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 boolean
the autoSizing to set

createBadge

public static FloatingActionButton createBadge(String text)
Creates a text badge

Parameters

text String
the text of the badge

Returns

a badge component

createFAB

public static FloatingActionButton createFAB(char icon)
a factory method to create a FloatingActionButton.

Parameters

icon char
one of the FontImage.MATERIAL_* constants

Returns

a FloatingActionButton instance

createFAB

public static FloatingActionButton createFAB(char icon, String uiid)
a factory method to create a FloatingActionButton.

Parameters

icon char
one of the FontImage.MATERIAL_* constants
uiid String
the uiid for the fab

Returns

a FloatingActionButton instance

setUIID

public void setUIID(String id)
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 String
UIID unique identifier for component type

styleChanged

public void styleChanged(String propertyName, Style source)

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 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 String
the property name that was changed
source Style
The changed Style object

createSubFAB

public FloatingActionButton createSubFAB(char icon, String text)
Adds a sub FAB to the FloatingActionButton instance. Once pressed all its sub FAB’s are displayed.

Parameters

icon char
one of the FontImage.MATERIAL_* constants
text String
the text of the sub FloatingActionButton

Returns

a FloatingActionButton instance for the sub FAB added

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

bindFabToContainer

public Container bindFabToContainer(Component cnt)
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 Component
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

public Container 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.

Parameters

cnt Component
the Container to add the FAB to
orientation int
one of Component.RIGHT/LEFT/CENTER
valign int
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

public void setText(String text)
Overriden to implement the caps mode #setCapsText(boolean) Sets the Label text

Parameters

text String
the string that the label presents.

fireActionEvent

protected void fireActionEvent(int x, int y)
Allows subclasses to override action event behavior for pointer coordinates.

Parameters

x int
the x position of the click if applicable (can be 0 or -1 otherwise)
y int
the y position of the click if applicable (can be 0 or -1 otherwise)

released

public void released(int x, int y)
Invoked to change the state of the button to the released state

Parameters

x int
the x position if a touch event triggered this, -1 if this isn’t relevant
y int
the y position if a touch event triggered this, -1 if this isn’t relevant

createPopupContent

protected Container createPopupContent(List<FloatingActionButton> fabs)
Creates the popup content container to display on the dialog.

Parameters

fabs List<FloatingActionButton>
List of sub FloatingActionButton

Returns

a Container that contains all fabs

showPopupDialog

protected void showPopupDialog(Dialog dialog)
Shows the popup Dialog with the sub FABs.

Parameters

dialog Dialog
the Dialog with all sub FAB’s Components

getFloatingActionTextUIID

public String getFloatingActionTextUIID()

Returns

the floatingActionTextUIID

setFloatingActionTextUIID

public void setFloatingActionTextUIID(String floatingActionTextUIID)

Parameters

floatingActionTextUIID String
the floatingActionTextUIID to set