Pular para o conteúdo
CrossFly é 100% open sourceSiga no GitHub
CrossFlyCrossFly
Começar

Folhas de cola

As decisões mais frequentes, condensadas. Todos os trechos compilam contra a API 2026.

Layouts — assinatura de add()

// VerticalLayout / HorizontalLayout — primeiro o tamanho, depois o componente
add(LAY_FILL, comp);   // -1f → preenche o espaço restante (o "elástico")
add(LAY_AUTO, comp);   //  0f → tamanho natural do conteúdo
add(0.2f, comp);       // >0  → 20% da dimensão total do contêiner

// GridLayout — TODAS as larguras, depois TODOS os componentes
add(0.35f, 0.65f, new Label("Nome"), new TextField(""));

// EvenlySpacedLayout — só o componente (espaça igualmente; não dimensiona)
add(icone1); add(icone2);

// RelativeLayout — âncoras (ver matriz abaixo)
add(comp, RelPos.AFTER, RelPos.CENTER_OF, RelSize.AUTOSIZE, RelSize.AUTOSIZE, refComp);

Detalhe por layout: ui/layouts/.

RelativeLayout — matriz

add(alvo, RelPos x, RelPos y, RelSize larg, RelSize alt [, Component ref] [, Gap outgap]);
RelPos (posição) RelSize (tamanho)
START · CENTER · END · AFTER · BEFORE AUTOSIZE (conteúdo)
CENTER_OF · END_OF · SAMEPOS FILL (pai − margem) · FIT (borda→ref)
AUTOPOS · AUTOPOSCENTERED · KEEPPOS SAMESIZE · KEEPSIZE

Relative — dimensões responsivas

Relative.ofFont(1.5f);                     // 1,5 × altura da fonte (escala com a UI)
Relative.ofScreen(0.8f);                   // 80% da tela
Relative.ofScreen(0.5f, ScreenSize.MIN);   // 50% do MENOR lado (adapta portrait/landscape)
Relative.ofPixels(24f);                    // pixel fixo (use por exceção)

Cores — ARGB 0xAARRGGBB

int opaco     = 0xFF2196F3;                       // alpha FF = totalmente visível
int invisivel = 0x002196F3;                       // ⚠️ alpha 00 → NÃO aparece
int meio      = ColorUtils.withAlpha(0xFF2196F3, 128);  // 50% transparente
int escuro    = ColorUtils.darker(0xFF2196F3, 0.2f);
int claro     = ColorUtils.lighter(0xFF2196F3, 0.2f);
int mistura   = ColorUtils.lerpColor(corA, corB, 0.5f);

Armadilha do alpha: um int sem o byte de alpha (0xRRGGBB) tem alpha 0 → o componente fica invisível. Sempre inclua 0xFF... para opaco.

Threading — voltar/rodar

Component.onUI(() -> { ... });               // volta à paint thread (de qualquer thread)
Main.runOnPaintThread(() -> { ... });         // idem, fora de um Component
Main.runOnPaintThreadAndWait(() -> { ... });  // idem, bloqueando até terminar
comp.onActionThread(c -> { ... });            // reage a um evento numa thread de fundo
Component.repaint();                          // pede um novo frame (render sob demanda)

Por quê: A paint thread.

Veja também

Esta página foi útil?