Skip to content

Describing the UI

Before an interface reacts or animates, it has to exist: screens, the shapes and texts on them, their places and their sizes. This chapter shows how you describe all of it in Java, as a tree of nodes inside a UI, on a canvas that JOID fits to any window. The Catalog shows every node with a capture, when you look for one.

A UI is a class that builds its nodes in init(); you open it, and JOID draws it until you close it.

JOID.open(new MenuUI());

Full file: Navigation.java

Read UIs to learn the life of a UI, how to keep it open and how to configure it.

Everything a UI shows is a node, created by a factory, configured by setters and attached to the UI or to another node.

RectNode.create(660, 490, 600, 100).color(ToolbarUI.SURFACE).attach(this);

Full file: ToolbarUI.java

Read Nodes and the tree to learn how to nest nodes and how positions follow the tree.

A node joins a UI, lives there for many frames and leaves; listeners run your code at each of these moments.

.onInit(event -> this.frames = 0L)
.onUpdate(event -> this.frames++)

Read Node lifecycle to learn when each listener runs and what to release when a node leaves.

You place every node on a 1920 × 1080 canvas of design pixels, and JOID fits it to the window.

RectNode
.create(0, 0, 0, 0)
.color(EdgesUI.ELEMENT)
.x(() -> super.getViewX())
.y(() -> super.getViewY())
.width(() -> super.getViewWidth())
.height(() -> super.getViewHeight())
.attach(this);

Full file: EdgesUI.java

Read The design canvas to learn how the canvas fits windows of any shape, how to reach their edges and how to zoom.

A node is placed and sized from its parent; anchors, zindex, visibility and copies refine it.

RectNode.create(60, 60, 200, 200).color(OrderUI.MUTED).zindex(1).attach(card);
RectNode.create(160, 100, 200, 200).color(OrderUI.ACCENT).attach(card);
RectNode
.create(340, 140, 200, 200)
.color(OrderUI.ELEMENT)
.body(front -> RectNode.create(-40, -40, 120, 120).color(OrderUI.MUTED).zindex(-1).attach(front))
.attach(card);

Full file: OrderUI.java

Read Position and size to learn how to size from a parent, keep a point fixed and choose what is on top.

A popup opens above the current screen and keeps the input until it closes; an overlay stays open while screens open and close.

@UIDataPopup(active = true)
public class ConfirmPopup extends UI {

Read Overlays and popups to learn how UIs stack, how a popup dims the screen and how an overlay takes input.

A node never moves its children; a layout node does, and any node can clip or scroll what goes beyond it.

RectNode
.create(20, 20, 360, 260)
.color(OverflowUI.ELEMENT)
.overflow(OverflowProperty.HIDDEN)
.body(area -> RectNode.create(40, 60, 360, 140).color(OverflowUI.ACCENT).attach(area))
.attach(card);

Full file: OverflowUI.java

Read Layout to learn the layout rule, groups, clipping and scrolling.

A flex node lines its children up in a column or a row, and grows to fit them.

FlexNode
.vertical(20, 20, 360)
.margin(10D)
.body(flex -> {
RectNode.create(0, 0, 200, 50).color(FlexCasesUI.ACCENT).attach(flex);
RectNode.create(0, 0, 120, 50).color(FlexCasesUI.ACCENT).attach(flex);
RectNode.create(0, 0, 280, 50).color(FlexCasesUI.ACCENT).attach(flex);
RectNode.create(0, 0, 160, 50).color(FlexCasesUI.ACCENT).attach(flex);
})
.attach(card);

Full file: FlexCasesUI.java

Read Flex layout to learn its rule, case by case.

A grid node fills rows of cells and wraps at its width.

GridNode
.create(20, 20, 360, 0)
.margin(10D)
.body(grid -> {
for (int i = 0; i < 9; i++) {
RectNode.create(0, 0, 80, 80).color(GridCasesUI.ACCENT).attach(grid);
}
})
.attach(card);

Full file: GridCasesUI.java

Read Grid layout to learn its rule, case by case.

A text node draws a text in a style that names its font, size and color.

TextNode.create(50, 50).text(Text.create("Hello JOID", title)).attach(card);

Full file: GreetingUI.java

Read Text to learn styles, alignment, long texts and measures.

Your application loads its own fonts, once.

public final class AppFonts {
public static final MsdfFont MONTSERRAT = MsdfFontLoader.load(
"fonts/Montserrat/Montserrat-Regular.ttf",
"fonts/Montserrat/Montserrat-Bold.ttf"
).join();
private AppFonts() {}
}

Full file: AppFonts.java

Read Fonts to learn how weights are picked and which kind of font to choose.

Markup styles parts of a string, and effects change its glyphs as they are drawn.

final TextInfo tagged = info.withMarkups(MarkupUI.MARKUP);
TextNode.create(50, 50).text(Text.create("Read the <b>terms</b>, then <em>accept</em> them", tagged)).attach(card);

Full file: MarkupUI.java

Read Text markup and effects to learn how to write a markup, an effect, a modifier and a converter.

A resource is an image, an animation or a video that a node draws or plays.

final Resource image = Resource.of("images/placeholder.png");

Full file: GalleryUI.java

Read Images and media to learn how to fit, tint and crop images, play videos, and which formats JOID reads.

Report a problem with this page