What's the best way to get text user-interfaces (ncurses-like) functionality in Java?

30,982

Solution 1

Since 2010 there is Lanterna :

Lanterna is a Java library allowing you to write easy semi-graphical user interfaces in a text-only environment, very similar to the C library curses but with more functionality. Lanterna is supporting xterm compatible terminals and terminal emulators such as konsole, gnome-terminal, putty, xterm and many more. One of the main benefits of lanterna is that it's not dependent on any native library but runs 100% in pure Java.

More here: https://github.com/mabe02/lanterna

Solution 2

You may want to go vote for this issue here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6351276

Essentially there is no good way to get ncurses-like functionality without JNI until this issue is addressed.

Solution 3

I'm using JavaTUI (http://sourceforge.net/projects/javatui/files/) in my several console java projects. It's best what i can find but it so far from perfect. I'm think there is not a good TUI implemetation in java world.

Solution 4

You can try Jexer - Java Text User Interface:

https://github.com/klamonte/jexer

Solution 5

Try java curses (sorry it uses JNI). I also tried to implement a short version of this library just to learn JNI , see http://plindenbaum.blogspot.com/2008/01/java-native-interface-jni-notebook.html. One could also imagine a specialized JPanel displaying a matrix of characters:

public class TPanel extends JPanel
{
private Vector<Vector<YourCharAndStyle>> rows;

protected void paintComponent(Graphics g)
 {
 //paint the characters
 (...)
 }

}
Share:
30,982
Anthony
Author by

Anthony

Updated on July 21, 2022

Comments

  • Anthony
    Anthony almost 2 years

    I need to implement a console application (possibly in Java) with ncurses-like functionality (such as navigating a menu and redrawing the whole screen).

    The only solutions that I can find to do this so far are CHARVA ("A Java Windowing Toolkit for Text Terminals"), tuipeer ("A Text User Interface for the Java AWT") and a really old Dr. Dobb's article ("A Text UI for the Java AWT ").

    So far, CHARVA is the best thing that I can find but I don't like the idea of it using JNI to wrap curses.

    Is there any standard way, say with AWT/Swing, to do do this? What other alternatives are there?