Skip to content

Quick Start

This page builds the smallest complete JOID program: a window with a button that counts its clicks. Then it tours what you use every day, one short section per topic, each with a link to the page that explains it.

The program of this page: at each click, the label follows the counter by itself.

Start from the project of Installation, with the LWJGL 3 jar, and set the main class to com.example.start.Main.

1. Add a font. JOID ships no font for your application (Fonts). Put any TrueType or OpenType file at src/main/resources/fonts/Montserrat/Montserrat-Regular.ttf; the program loads it from the classpath.

2. Write the UI. A UI is a class that extends UI and creates its nodes in init():

CounterUI.java
package com.example.start;
import dev.joid.lib.color.Color;
import dev.joid.lib.draw.text.Text;
import dev.joid.lib.font.TextInfo;
import dev.joid.lib.font.impl.msdf.MsdfFont;
import dev.joid.lib.font.impl.msdf.MsdfFontLoader;
import dev.joid.lib.signal.impl.primitive.IntegerSignal;
import dev.joid.lib.ui.core.UI;
import dev.joid.lib.ui.node.effect.impl.RoundedNodeEffect;
import dev.joid.lib.ui.node.impl.shape.RectNode;
public class CounterUI extends UI {
private static final MsdfFont FONT = MsdfFontLoader.load(
"fonts/Montserrat/Montserrat-Regular.ttf"
).join();
private static final Color ACCENT = new Color(91, 140, 255).lock();
private static final Color ACTIVE = new Color(125, 164, 255).lock();
private static final Color ON_ACCENT = new Color(14, 16, 20).lock();
private final IntegerSignal clicks = new IntegerSignal(0);
@Override
public void init() {
final TextInfo label = TextInfo.create(CounterUI.FONT, 40F).color(CounterUI.ON_ACCENT);
RectNode
.create(760, 480, 400, 120)
.color(CounterUI.ACCENT)
.hoveredColor(CounterUI.ACTIVE)
.effect(RoundedNodeEffect.create(12F))
.onClick(event -> this.clicks.increment())
.label(Text.create("Clicks: " + this.clicks.get(), label))
.attach(this);
}
}
  • MsdfFontLoader loads the font; the first run on a machine takes a few seconds, and later runs read a cache.
  • lock() keeps a shared color from being changed by accident (Keep a palette safe).
  • RectNode.create(760, 480, 400, 120) is a 400 × 120 rectangle at the center of the 1920 × 1080 canvas, and attach(this) adds it to the UI.
  • onClick(...) increments the signal clicks, and the label that reads this.clicks.get() follows it: Signals explains how.

3. Write the program. JOID never creates a window: your program creates it with GLFW, hands it to the backend, opens the UI and calls frame() in its loop.

Main.java
package com.example.start;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import dev.joid.backend.lwjgl3.GlContextRequest;
import dev.joid.backend.lwjgl3.Lwjgl3Backend;
import dev.joid.lib.JOID;
import dev.joid.lib.bridge.BridgeHandler;
import dev.joid.lib.bridge.ui.WindowUIBridge;
public final class Main {
private Main() {}
public static void main(final String[] arguments) {
GLFWErrorCallback.createPrint(System.err).set();
if (!GLFW.glfwInit()) {
throw new IllegalStateException("Unable to initialize GLFW");
}
GlContextRequest.CORE_33.apply();
final long window = GLFW.glfwCreateWindow(1280, 720, "JOID", 0L, 0L);
if (window == 0L) {
throw new IllegalStateException("Unable to create the window");
}
GLFW.glfwMakeContextCurrent(window);
GL.createCapabilities();
final Lwjgl3Backend backend = Lwjgl3Backend.create(window).register();
JOID.open(new CounterUI());
while (!GLFW.glfwWindowShouldClose(window)) {
GLFW.glfwPollEvents();
backend.frame();
GLFW.glfwSwapBuffers(window);
}
BridgeHandler.UI.getBridge(WindowUIBridge.class).closeAll();
GLFW.glfwDestroyWindow(window);
GLFW.glfwTerminate();
}
}
  • GlContextRequest.CORE_33.apply() asks GLFW for an OpenGL 3.3 core context with the depth and stencil buffers that JOID needs.
  • register() needs the context current on this thread, because it creates GPU objects at once.
  • frame() draws one frame of every open UI, and glfwSwapBuffers shows it.
  • closeAll() closes the open UIs once the window closes, so that what they keep reaches the disk.

4. Run it with gradle run. The console prints [JOID] 8.0.0 loaded in dev mode, … (Installation), and the window shows the button: each click increments the counter, and Escape closes the UI.

This program runs on LWJGL 3. With Vulkan or LWJGL 2, take the complete program of your backend from Start the other backends and open CounterUI in it; the rest of this page does not change, and the tutorial changes only Main: apply its highlighted lines to your program.

Check, in this order:

  1. ExceptionInInitializerError in CounterUI: the font file is not at src/main/resources/fonts/Montserrat/Montserrat-Regular.ttf, and the stack trace reads The asset fonts/Montserrat/Montserrat-Regular.ttf is not found in the classpath nor as a file.
  2. UnsatisfiedLinkError, NoClassDefFoundError, or a thread error on macOS: an LWJGL module or its natives are missing; If it does not work of Installation gives the cause of each.
  3. Unable to create the window: the driver offers no OpenGL 3.3 core context; call GlContextRequest.COMPATIBILITY.apply() instead, to take the default context of the driver.
  4. The window stays black or empty: Troubleshooting lists the checks by symptom.

Most examples of Learn and of the guides are UIs, and the “Full file” link under each one shows its class without a main; the few that start JOID themselves, in Running your UI, have their own main. An example that uses other classes of its package, such as a markup, a node or a store, needs them too: copy the whole package of the example. Most of them write their text with ExampleFont.REGULAR, a family of two faces of Montserrat loaded once for every example. Add this class to the package com.example, and put Montserrat-Bold.ttf next to the Montserrat-Regular.ttf of step 1:

ExampleFont.java
package com.example;
import dev.joid.lib.font.impl.msdf.MsdfFont;
import dev.joid.lib.font.impl.msdf.MsdfFontLoader;
public final class ExampleFont {
public static final MsdfFont REGULAR = MsdfFontLoader.load(
"fonts/Montserrat/Montserrat-Regular.ttf",
"fonts/Montserrat/Montserrat-Bold.ttf"
).join();
private ExampleFont() {}
}

Your application loads its own family the same way (Fonts): use it wherever an example names ExampleFont.REGULAR.

Then add this launcher next to Main. It opens the UI whose class you name, gives the tooltips a text style, and closes the open UIs when the window closes:

Launcher.java
package com.example.start;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import com.example.ExampleFont;
import dev.joid.backend.lwjgl3.GlContextRequest;
import dev.joid.backend.lwjgl3.Lwjgl3Backend;
import dev.joid.lib.JOID;
import dev.joid.lib.bridge.BridgeHandler;
import dev.joid.lib.bridge.ui.WindowUIBridge;
import dev.joid.lib.color.Color;
import dev.joid.lib.font.TextInfo;
import dev.joid.lib.ui.core.UI;
public final class Launcher {
private static final Color TEXT = new Color(231, 233, 238).lock();
private Launcher() {}
public static void main(final String[] arguments) throws ReflectiveOperationException {
GLFWErrorCallback.createPrint(System.err).set();
if (!GLFW.glfwInit()) {
throw new IllegalStateException("Unable to initialize GLFW");
}
GlContextRequest.CORE_33.apply();
final long window = GLFW.glfwCreateWindow(1280, 720, "JOID", 0L, 0L);
if (window == 0L) {
throw new IllegalStateException("Unable to create the window");
}
GLFW.glfwMakeContextCurrent(window);
GL.createCapabilities();
final Lwjgl3Backend backend = Lwjgl3Backend.create(window).register();
final WindowUIBridge bridge = BridgeHandler.UI.getBridge(WindowUIBridge.class);
bridge.hoverInfo(TextInfo.create(ExampleFont.REGULAR, 20F).color(Launcher.TEXT));
JOID.open(Class.forName(arguments[0]).asSubclass(UI.class).getConstructor().newInstance());
while (!GLFW.glfwWindowShouldClose(window)) {
GLFW.glfwPollEvents();
backend.frame();
GLFW.glfwSwapBuffers(window);
}
bridge.closeAll();
GLFW.glfwDestroyWindow(window);
GLFW.glfwTerminate();
}
}

Set the main class to com.example.start.Launcher, then name the UI on the command line:

Terminal window
gradle run --args="com.example.start.CounterUI"

An example that reads a file reads it from the resources, under the path that its code names. The resources of the examples hold every one of them: fonts, images, a video and 3D models. The exception is an example that reads the disk with new File(...): put a file of yours at that path, from the working directory. Copy the folders you need into your src/main/resources, under the same paths.

JOID draws no control by itself: each example of a control gives it its parts, the nodes that draw it, where it creates it.

Every position and size is in design pixels, on a canvas of 1920 × 1080. JOID scales the whole canvas to the window, so you copy coordinates from your mockup as they are. Resize the window of the program above: the button stays centered and keeps its proportions.

Read The design canvas to fit the canvas to a window of any shape.

A node is a shape, a text, an image, a control or a container. body(...) creates the children of a node, and a child is positioned relative to its parent.

Read Nodes and the tree, then Position and size. The Catalog shows every node that JOID offers.

The examples of the rest of this page come from one UI, TourUI. Its nodes each sit in a card of their own, body(card -> ...), and the fields and the lines of init() that they read are shown above them, except its color constants: paste each one at the same place in your UI with colors of your own, or open its full file.

A FlexNode places its children one after the other, so you compute no position:

FlexNode
.horizontal(60, 110, 80)
.margin(20D)
.body(flex -> {
RectNode.create(0, 0, 80, 80).color(TourUI.ACCENT).attach(flex);
RectNode.create(0, 0, 80, 80).color(TourUI.ACCENT).attach(flex);
RectNode.create(0, 0, 80, 80).color(TourUI.ACCENT).attach(flex);
})
.attach(card);

Full file: TourUI.java

Three blue squares in a row on a dark card, 20 design pixels apart

The row places each square after the previous one.

Read Layout, Flex layout and Grid layout.

A TextNode draws a Text, built from a string and a TextInfo: the font, the size, the weight and the color. label(...), in the program above, centers a text on any node.

Read Text and Fonts, then Text markup and effects to style part of a text.

A ResourceNode draws an image, an animated GIF or WebP, or an SVG, loaded with Resource:

ResourceNode
.create(110, 50, 200, 200)
.resource(Resource.of("images/placeholder.png"))
.attach(card);

Full file: TourUI.java

A grey placeholder image crossed by two diagonals, on a dark card

The image fills the size of the node.

Read Images and media, which also plays videos and sounds.

hoveredColor(...) and onClick(...) in the program above are the most common reactions. Nodes also react to the pointer entering and leaving, to drags, to the wheel and to keys.

Read Events, Hover, tooltips and cursors, Drag and drop and Keyboard and shortcuts. Controls and Text fields cover checkboxes, sliders and text input.

A node set from an expression that reads a signal follows that signal. map(...) derives a signal from another:

private final IntegerSignal clicks = new IntegerSignal(0);
private final ComputedSignal<Boolean> many = this.clicks.map(count -> count >= 3);

Full file: TourUI.java

RectNode
.create(110, 100, 200, 100)
.color(this.many.get() ? TourUI.ACCENT : TourUI.ELEMENT)
.onClick(event -> this.clicks.increment())
.attach(card);

Full file: TourUI.java

At the third click, the derived signal turns true and the color follows.

Read Signals, then Derived values and Rebuilding the tree.

A field annotated with UIProperty keeps its value from one run to the next. JOID saves it when the UI closes (Close the UIs before the program ends):

@UIProperty
private int visits;

Full file: TourUI.java

Increment it in init(), which runs at each opening, and show it in a text, "Visit " + this.visits:

this.visits++;

Full file: TourUI.java

Read Stores and remembered properties to share values between UIs, and Where JOID stores files to find the files.

An effect changes how a node is drawn, never where it sits:

RectNode
.create(110, 70, 200, 160)
.color(TourUI.ACCENT)
.effect(RoundedNodeEffect.create(24F))
.effect(ShadowNodeEffect.create(TourUI.SHADOW, 24F).offsetY(8D))
.attach(card);

Full file: TourUI.java

A blue rectangle with rounded corners and a soft shadow below it, on a dark card

Two effects on one rectangle: the shadow follows the rounded shape.

Read Colors and styling, then Effects.

A TweenAnimator moves a value over time; it is a signal, so a setter that reads it in an expression follows it:

final TweenAnimator slide = TweenAnimator
.create(0F)
.sequence(800F, 1F, TweenEquations.SINE_IN_OUT)
.repeatYoyo(BaseTween.INFINITY, 0F)
.start();

Full file: TourUI.java

RectNode
.create(60, 110, 80, 80)
.color(TourUI.ACCENT)
.x(60D + 220D * slide.get())
.attach(card);

Full file: TourUI.java

The animator goes from 0 to 1 in 800 ms, then plays back and forth forever.

An animator that repeats forever keeps running after its UI closes: the full file stops it with slide.clear() when its card detaches (Chain, repeat and replay).

Read Animation, then Transitions to animate a UI when it opens and closes.

A popup is a UI opened above the current one. The annotation UIDataPopup, @UIDataPopup(active = true), turns a UI into a popup, background = true of UIData dims the screen behind it, and JOID.open opens it:

@UIData(background = true)
@UIDataPopup(active = true)
public class NoticeUI extends UI {
private static final Color ELEMENT = new Color(38, 43, 53).lock();
private static final Color SURFACE = new Color(23, 26, 33).lock();
@Override
public void init() {
RectNode
.create(760, 390, 400, 300)
.color(NoticeUI.SURFACE)
.effect(RoundedNodeEffect.create(12F))
.effect(BorderNodeEffect.create(NoticeUI.ELEMENT, 1.5F))
.onClick(event -> JOID.close(this))
.attach(this);
}
}

Full file: NoticeUI.java

RectNode
.create(110, 100, 200, 100)
.color(TourUI.ELEMENT)
.onClick(event -> JOID.open(new NoticeUI()))
.attach(card);

Full file: TourUI.java

The popup opens above the screen, which stays open behind its backdrop; a click on the popup closes it.

Read UIs, then Overlays and popups.

With the dev jar, F3 shows the inspector, and Ctrl+R or F5 runs init() again. To reload the code you change, start the application in debug mode from your IDE: hot reload then reloads the UI by itself. JOID also prints a warning that starts with [JOID] when a call cannot work, with its cause and its fix.

Read Dev tools.

  • Build a complete menu, lesson by lesson, in the Tutorial.
  • Learn the ideas behind JOID in How JOID works, then follow the Learn chapters in order.

Report a problem with this page