This page was machine-translated from Portuguese and may contain errors. The Portuguese version is canonical.
Cheat sheets
The most frequent decisions, condensed. All snippets compile against the 2026 API.
Layouts — add() signature
// VerticalLayout / HorizontalLayout — first the size, then the component
add(LAY_FILL, comp); // -1f → fills the remaining space (the "elastic")
add(LAY_AUTO, comp); // 0f → content's natural size
add(0.2f, comp); // >0 → 20% of the container's total dimension
// GridLayout — ALL the widths, then ALL the components
add(0.35f, 0.65f, new Label("Nome"), new TextField(""));
// EvenlySpacedLayout — only the component (spaces evenly; does not size)
add(icone1); add(icone2);
// RelativeLayout — anchors (see matrix below)
add(comp, RelPos.AFTER, RelPos.CENTER_OF, RelSize.AUTOSIZE, RelSize.AUTOSIZE, refComp);
Detail per layout: ui/layouts/.
RelativeLayout — matrix
add(alvo, RelPos x, RelPos y, RelSize larg, RelSize alt [, Component ref] [, Gap outgap]);
RelPos (position) |
RelSize (size) |
|---|---|
START · CENTER · END · AFTER · BEFORE |
AUTOSIZE (content) |
CENTER_OF · END_OF · SAMEPOS |
FILL (parent − margin) · FIT (edge→ref) |
AUTOPOS · AUTOPOSCENTERED · KEEPPOS |
SAMESIZE · KEEPSIZE |
Relative — responsive dimensions
Relative.ofFont(1.5f); // 1.5 × font height (scales with the UI)
Relative.ofScreen(0.8f); // 80% of the screen
Relative.ofScreen(0.5f, ScreenSize.MIN); // 50% of the SMALLER side (adapts portrait/landscape)
Relative.ofPixels(24f); // fixed pixel (use as an exception)
Colors — ARGB 0xAARRGGBB
int opaco = 0xFF2196F3; // alpha FF = fully visible
int invisivel = 0x002196F3; // ⚠️ alpha 00 → does NOT appear
int meio = ColorUtils.withAlpha(0xFF2196F3, 128); // 50% transparent
int escuro = ColorUtils.darker(0xFF2196F3, 0.2f);
int claro = ColorUtils.lighter(0xFF2196F3, 0.2f);
int mistura = ColorUtils.lerpColor(corA, corB, 0.5f);
Alpha trap: an
intwithout the alpha byte (0xRRGGBB) has alpha 0 → the component becomes invisible. Always include0xFF...for opaque.
Threading — return/run
Component.onUI(() -> { ... }); // returns to the paint thread (from any thread)
Main.runOnPaintThread(() -> { ... }); // same, outside of a Component
Main.runOnPaintThreadAndWait(() -> { ... }); // same, blocking until it finishes
comp.onActionThread(c -> { ... }); // reacts to an event on a background thread
Component.repaint(); // requests a new frame (render on demand)
Why: The paint thread.
See also
- Enums and
UIConstants· Layouts · Colors (Ch. 11)
Was this page helpful?Thanks for the feedback!