Page Details
access: Public published: 2021-01-06 creationDate: 2021-01-06 modifiedDate: 2025-09-21 type: Blog Blog/Post description: Code snippet for writing a TUI in Java using Lanterna digitalGarden: Evergreen
[!warning] Hey, it’s you from 2025 Don’t do this. Don’t hurt yourself. You want to write a TUI? Don’t use Java. Use Python or Rust. That summer when you thought it was a fun idea is over.
tldr: Here’s a code snippet of a fullscreen terminal window using Lanterna.
Lanterna is an easy way to make text only user interfaces in Java that I highly recommend. One thing that took me too long to find was how to make a window fullscreen. Add:
yourWindow.setHints(java.util.Collections.singleton(Window.Hint.FULL_SCREEN));Here’s it in a minimal example:
import java.io.IOException;
import com.googlecode.lanterna.gui2.*;
import com.googlecode.lanterna.screen.*;
import com.googlecode.lanterna.terminal.*;
public class TUI {
public static void main(String[] args) {
MultiWindowTextGUI gui;
Screen screen;
BasicWindow window;
try (Terminal terminal = new DefaultTerminalFactory().createTerminal()) {
screen = new TerminalScreen(terminal);
screen.startScreen();
gui = new MultiWindowTextGUI(screen);
window = new BasicWindow();
window.setComponent(new Label("Hello, fullscreen!"));
// Set window to use fullscreen hint
window.setHints(java.util.Collections.singleton(Window.Hint.FULL_SCREEN));
gui.addWindowAndWait(window);
} catch (IOException ex) {
}
}
}Note: There are other hints you can use in Window.Hint you can use. Put them in a collection and pass them to the setHints method. I like Window.Hint.NO_DECORATIONS.
Note: Note: As told in the documentation, “Please note that it’s up to the window manager if these hints will be honored or not.”
Resources
Tags: Code_Snippet, Commandline, Programming_Language/Java, Terminal, TUI