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 fordelaymilliseconds, with a fade. Static method (Hintis 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)— passingmessage == nullhides the current toast immediately.Hint.INFINITE— constantInteger.MAX_VALUE: keeps it visible (with fade-in) until you hide it manually.Hint.INFINITE_NOANIM— constantInteger.MIN_VALUE: keeps it visible without animation.
Global configuration (public static fields):
Hint.backColor,Hint.foreColor,Hint.position(defaultRelative.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
MainWindowskeleton 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 nohide()method; to hide it, callHint.show(null, ...). The toast is rendered by an internalToastWindow(a subclass ofWindow) shown on theEventsProcessorstack, so it appears over the current screen without you managing anything.
Dig deeper
- Widget page: Hint · Canonical source: Chapter 16
- Sister modal dialogs: Confirm with Alert · Actions menu