Skip to content
CrossFly is 100% open sourceFollow us on GitHub
CrossFlyCrossFly
Get started

This page was machine-translated from Portuguese and may contain errors. The Portuguese version is canonical.

How to show a Hint (toast)

Purpose. Show a short, temporary message (“toast” style) that appears over the screen, does not block interaction and disappears on its own after a while. Use it for quick confirmations (“Saved”, “Copied”), light warnings and status. It replaces the old Toast concept.

APIs used

  • Hint.show(String message, int delay) — shows the toast for delay milliseconds, with a fade. Static method (Hint is not instantiated).
  • Hint.show(message, delay, Window parentWindow) — same thing, anchored to a specific window (default: the top window of the stack).
  • Hint.show(message, delay, parentWindow, Relative at, Gap innerGap) — full control over vertical position and inner padding.
  • Hint.show(null, delay) — passing message == null hides the current toast immediately.
  • Hint.INFINITE — constant Integer.MAX_VALUE: keeps it visible (with fade-in) until you hide it manually.
  • Hint.INFINITE_NOANIM — constant Integer.MIN_VALUE: keeps it visible without animation.

Global configuration (public static fields): Hint.backColor, Hint.foreColor, Hint.position (default Relative.ofScreen(0.85f), near the bottom), Hint.fade, Hint.font. Changing these fields affects all subsequent toasts.

Complete example (copy, paste and run)

package com.exemplo;

import dev.crossfly.ui.*;
import dev.crossfly.ui.layout.*;

/** Runnable main screen. Point the launcher (classname) and run: gradlew :lwjgl3:run */
public class MainWindow extends Window
{
   @Override
   public void onShow() throws Exception
   {
      super.onShow();
      setLayout(new VerticalLayout());

      // A button that triggers the toast when tapped
      Button btn = new Button("Salvar");
      btn.onAction(origin ->
      {
         // Simple toast: appears for 2 seconds and fades out
         Hint.show("Registro salvo", 2000);
      });
      add(LAY_FILL, btn);
   }
}

The snippet below shows just the core. To run it, place it in the MainWindow skeleton above.

Minimal snippet

// Simple toast: appears for 2 seconds and fades out
Hint.show("Registro salvo", 2000);

// Infinite toast (stays on screen until you tell it to disappear)
Hint.show("Sincronizando...", Hint.INFINITE);
// ...when done:
Hint.show(null, 0);   // message == null hides the current toast

// Positioned at the top, with custom inner padding
Hint.show("No topo", 1500, null, Relative.START, Gap.ofFont(1f, 0.5f, 1f, 0.5f));

Verification note (2026 code). The real signature in source is Hint.show(String, int) and overloads — there is no hide() method; to hide it, call Hint.show(null, ...). The toast is rendered by an internal ToastWindow (a subclass of Window) shown on the EventsProcessor stack, so it appears over the current screen without you managing anything.

Dig deeper

Was this page helpful?