Interface Tooltip

All Known Implementing Classes:
Tooltip.Custom, Tooltip.Lines

public sealed interface Tooltip permits Tooltip.Lines, Tooltip.Custom
What a host shows near the pointer while it rests on a component; see HasTooltip.setTooltip(Tooltip).

The host shows a tooltip once the pointer has rested on its component for the host's tooltip delay, or at once when the pointer moves straight from another component's tooltip. The delay is the one the adapter sets, else the theme's "tooltip.delay", else 500L milliseconds. It moves with the pointer: its top-left corner sits "tooltip.offset.x" units right of and "tooltip.offset.y" units below the pointer's whole-unit position (12 right and 12 above by default), flipped to the left side when it would leave the host on the right, and kept inside the host. It hides while a drag is in progress. A tooltip draws above the screen and every overlay, and takes no input.

There are two kinds. Tooltip.Lines, made by text(Text), text(String) and lines(List), is drawn by Strata: on the "tooltip.background" paint inside the "tooltip.padding" insets, 4 units on every side by default, with its plain parts in the "tooltip.text" text style and styled parts changing it (see Text). Tooltip.Custom, made by of(Function), is a component built afresh each time the tooltip shows, drawn with no box around it. Engine adapters can offer factory methods that build tooltips from engine objects, such as the lines an engine shows for one of its items.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    A component built when the tooltip appears.
    static final record 
    Lines of text, resolved against the theme's tooltip style each time the tooltip appears.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    How long, in milliseconds, the pointer rests on a component before its tooltip shows, unless the adapter or the theme sets another delay.
    static final String
    Style key for the box behind a Tooltip.Lines tooltip (paint, optional).
    static final String
    Style key for placing a tooltip below its component rather than beside the pointer (metric, optional): any value but 0 turns it on.
    static final String
    Style key for the gap of a tooltip placed below its component (metric, optional), in UI units.
    static final String
    Style key for the overlap of a tooltip placed below its component (metric, optional), in UI units.
    static final String
    Style key for how long the pointer rests on a component before its tooltip shows (metric, optional), in milliseconds.
    static final String
    Style key for a second layer drawn over the "tooltip.background" of a Tooltip.Lines tooltip, such as an edge (paint, optional).
    static final String
    Style key for where a tooltip's left edge sits, right of the pointer (metric, optional), in UI units.
    static final String
    Style key for where a tooltip's top edge sits, below the pointer (metric, optional), in UI units; a negative value puts it above.
    static final String
    Style key for how far the background and frame of a Tooltip.Lines tooltip reach past its box (insets, optional), for paints whose images have a margin of their own.
    static final String
    Style key for the space between a Tooltip.Lines tooltip's edges and its text (insets, optional).
    static final String
    Style key for the text of a Tooltip.Lines tooltip (text style, optional).
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static Tooltip
    lines(List<? extends Text> lines)
    Returns a tooltip of lines.
    static Tooltip
    of(Function<ComponentFactory, ? extends Component<?>> builder)
    Returns a tooltip whose content is a component, built again each time the tooltip appears.
    static Tooltip
    text(String text)
    Returns a tooltip of literal text in the theme's tooltip style.
    static Tooltip
    text(Text text)
    Returns a tooltip of text.
  • Field Details

    • STYLE_BACKGROUND

      static final String STYLE_BACKGROUND
      Style key for the box behind a Tooltip.Lines tooltip (paint, optional). If it is missing, the box is a dark fill with a one-unit purple edge.
      See Also:
    • STYLE_TEXT

      static final String STYLE_TEXT
      Style key for the text of a Tooltip.Lines tooltip (text style, optional). Falls back to the default style.
      See Also:
    • STYLE_PADDING

      static final String STYLE_PADDING
      Style key for the space between a Tooltip.Lines tooltip's edges and its text (insets, optional). Defaults to 4 on every side.
      See Also:
    • STYLE_FRAME

      static final String STYLE_FRAME
      Style key for a second layer drawn over the "tooltip.background" of a Tooltip.Lines tooltip, such as an edge (paint, optional). Defaults to none.
      See Also:
    • STYLE_OUTSET

      static final String STYLE_OUTSET
      Style key for how far the background and frame of a Tooltip.Lines tooltip reach past its box (insets, optional), for paints whose images have a margin of their own. The box, which is placed and kept inside the host, is the text and its padding. Defaults to none.
      See Also:
    • STYLE_DELAY

      static final String STYLE_DELAY
      Style key for how long the pointer rests on a component before its tooltip shows (metric, optional), in milliseconds. A delay the adapter sets wins. Defaults to 500L.
      See Also:
    • STYLE_OFFSET_X

      static final String STYLE_OFFSET_X
      Style key for where a tooltip's left edge sits, right of the pointer (metric, optional), in UI units. When flipped to the left side, its right edge sits this far left of the pointer. Defaults to 12.
      See Also:
    • STYLE_OFFSET_Y

      static final String STYLE_OFFSET_Y
      Style key for where a tooltip's top edge sits, below the pointer (metric, optional), in UI units; a negative value puts it above. Defaults to -12.
      See Also:
    • STYLE_BELOW

      static final String STYLE_BELOW
      Style key for placing a tooltip below its component rather than beside the pointer (metric, optional): any value but 0 turns it on. Defaults to 0. The left edge still follows "tooltip.offset.x". With the pointer at height p, the component's top at t, its bottom at b and its height h, the box's top is p + e(|p + o - t|), where e(d) eases from h - o at a distance of 0 to g at a distance of h or more and rounds to a whole unit, o is "tooltip.below.overlap" and g is "tooltip.below.gap". So the box sits just below the component and moves a little with the pointer. When the host has no room for the box below b + h, less g, the box's bottom goes to p - e(|p + o - b|) instead, above the pointer.
      See Also:
    • STYLE_BELOW_OVERLAP

      static final String STYLE_BELOW_OVERLAP
      Style key for the overlap of a tooltip placed below its component (metric, optional), in UI units. See "tooltip.below". Defaults to 3.
      See Also:
    • STYLE_BELOW_GAP

      static final String STYLE_BELOW_GAP
      Style key for the gap of a tooltip placed below its component (metric, optional), in UI units. See "tooltip.below". Defaults to 5.
      See Also:
    • DEFAULT_DELAY_MILLIS

      static final long DEFAULT_DELAY_MILLIS
      How long, in milliseconds, the pointer rests on a component before its tooltip shows, unless the adapter or the theme sets another delay.
      See Also:
  • Method Details

    • text

      static Tooltip text(Text text)
      Returns a tooltip of text.
      Parameters:
      text - the text; \n starts a new line
      Returns:
      the tooltip
    • text

      static Tooltip text(String text)
      Returns a tooltip of literal text in the theme's tooltip style.
      Parameters:
      text - the text; \n starts a new line
      Returns:
      the tooltip
    • lines

      static Tooltip lines(List<? extends Text> lines)
      Returns a tooltip of lines.
      Parameters:
      lines - the lines, top to bottom; a \n inside one starts another
      Returns:
      the tooltip
    • of

      static Tooltip of(Function<ComponentFactory, ? extends Component<?>> builder)
      Returns a tooltip whose content is a component, built again each time the tooltip appears.
      Parameters:
      builder - makes the content with the host's factory
      Returns:
      the tooltip