Skip to content

Creating JME3 User Interfaces with Nifty GUI

nifty-gui-13.png

You may want your players to press a button to save a game, you want a scrolling text field for highscores, a text label to display the score, drop-downs to select keymap preferences, or checkboxes to specify multi-media options. Usually you solve these tasks by using Swing controls. Although it is possible to embed a jME3 canvas in a Swing GUI, a 3D game typically runs full-screen, or in a window of its own.

This document introduces you to Nifty GUI, a Java library for building interactive graphical user interfaces (GUIs) for games or similar applications. Nifty GUI (the de.lessvoid.nifty package) is well integrated with jME3 through the com.jme3.niftygui package. You define the base GUI layout in XML, and control it dynamically from your Java code. Add the jme3-niftygui module and its dependencies to your project. For other UI options, see community UI modules.

Tutorial Overview

Learn to add a Nifty GUI to your jME3 game by going through this multi-part tutorial:

  1. Understand the Nifty GUI Concepts described on this page.

  2. Browse this short list of Best Practices

  3. Lay out your graphical user interface:

  4. Integrate the GUI into the game:

  5. Interact with the GUI from Java

Must Know: Nifty GUI Concepts

nifty-screen-layer-panel.png

Nifty GUIs are made up of the following elements:

  • A Nifty GUI contains one or more screens.

  • Only one screen is visible at a time.

  • Give screens unique IDs. The ID passed to nifty.fromXml(...) selects the first screen; the examples here use start.

  • Screen are controlled by a Java Controller class.

  • A screen contains one or more layers.

  • Layers are containers that impose alignment on their contents (vertical, horizontal, or centered)

  • Layers can overlap (z-order), and cannot be nested.

  • A layer contains panels.

  • Panels are containers that impose alignment on their contents (vertical, horizontal, or centered)

  • Panels can be nested, and cannot overlap.

  • A panel contains images, text, or controls (buttons, etc).

JME-Nifty Sample Code

External Documentation

Learn more from the NiftyGUI page:

Nifty Logging (Nifty 1.4.2)

If you want to disable the nifty log lines, add this code after you created nifty:

Logger.getLogger("de.lessvoid.nifty").setLevel(Level.SEVERE);
Logger.getLogger("NiftyInputEventHandlingLog").setLevel(Level.SEVERE);