Package totalcross.ui

Class ToolTip

  • All Implemented Interfaces:
    MouseListener, PenListener, TextControl

    public class ToolTip
    extends Label
    implements PenListener, MouseListener
    Displays a tooltip when user holds the pen in the control. On Windows and Linux desktop, the tooltip is also shown when the mouse stays over a control.

    The default popup delay is 1000ms and the amount of time it will be displayed is 2000 ms; a pen up also hides the tip.

    You can change some properties of the tooltip: borderColor, insideGap, distX, distY, millisDelay, millisDisplay. See their javadocs for details.

    Example:

     ToolTip.distX = 10; // 0 by default
     ToolTip.distY = 4;  // 0 by default
     ToolTip.insideGap = 8; // 4 by default
     Button b;
     add(b = new Button("Hello Tooltip!"),CENTER,BOTTOM);
    ToolTip t = new ToolTip(b, "Hi, this is a button");
    t.borderColor = 0x00FF00; // -1 (none) by default t.millisDelay = 500; // 1000 by default t.millisDisplay = 4000; // 2000 by default t.setBackColor(Color.getRGB(250,0,0)); // same as control's container by default
    The tooltip can have multiple lines, just split them using the char '\n' in your message.
    Example :
     ToolTip t = new ToolTip(control, "Hi!\nIt's Me");
     
    A ControlEvent.PRESSED event will be dispatched to the attached control right before the text is shown. You can then set the tip to a new value using setText; setting to an empty string will disable the tooltip at that moment. Calling setControlRect also changes the rectangle around which the tooltip will be displayed. In Android UI, the ToolTip is displayed with a round border.
    • Field Detail

      • insideGap

        public static int insideGap
        The gap between the border and the text. Common to all tooltips.
      • distX

        public static int distX
        The x distance between the tip and the control, 0 by default. Common to all tooltips.
      • distY

        public static int distY
        The y distance between the tip and the control, 0 by default. Common to all tooltips.
      • millisDelay

        public int millisDelay
        The amount of time that the pen must be down until the tip pops up (by default, 1000ms)
      • millisDisplay

        public int millisDisplay
        The amount of time that the tip will be shown (by default, 2000ms)
      • borderColor

        public int borderColor
        The border color. By default, it is -1 and no border is shown
    • Constructor Detail

      • ToolTip

        public ToolTip​(Control control,
                       java.lang.String message)
        Constructor
        Parameters:
        control - the control which supports the tip. If null, you must call setControlRect and show by your own.
        message - the message which will be written in the tip. You can make multiLine, using \n character like in the Label control.
    • Method Detail

      • dontShowTipOnMouseEvents

        public void dontShowTipOnMouseEvents()
        Stop using mouse events to show the tooltip.
        Since:
        TotalCross 1.27
      • split

        @Deprecated
        public static java.lang.String split​(java.lang.String msg,
                                             FontMetrics fm)
        Deprecated.
        The split is done automatically
        Use this handy method to split the text in order to correctly fit the window. Here's a sample:
         String msg = "a very long text that will be split to fit in the window";
         new ToolTip(control, ToolTip.split(msg, fm));
         
        Make sure that fm will be the font's FontMetrics (if you plan to change the font after calling the constructor).
        Since:
        TotalCross 1.2
      • setControlRect

        public void setControlRect​(Rect r)
        Change the control rect to the given one. By default, its used the absolute rectangle of the control passed in the constructor. The placement of the tooltip will be defined based on it, in a way that the control is not obscured.
      • onEvent

        public void onEvent​(Event e)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Label
        Parameters:
        e - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • show

        public void show()
        Shows the tooltip. If you want to show the tooltip programatically, you must do something like:
         toolTip.setText(msg);
         toolTip.setControlRect(lbCompany.getAbsoluteRect());
         toolTip.show();
         
      • hide

        public void hide()
        Hides the tooltip.
      • onPaint

        public void onPaint​(Graphics g)
        Description copied from class: Label
        Called by the system to draw the button.
        Overrides:
        onPaint in class Label
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • reposition

        public void reposition()
        Description copied from class: Control
        Reposition this control, calling again setRect with the original parameters.
        Overrides:
        reposition in class Control
      • mouseWheel

        public void mouseWheel​(MouseEvent e)
        Description copied from interface: MouseListener
        The event type for a mouse wheel moving down. This is a hardware event.
        Specified by:
        mouseWheel in interface MouseListener