Skip to content

GUI Elements

William Wood edited this page Mar 6, 2019 · 9 revisions

GUI Elements

To make cohesive user-interfaces with minimal effort, JISA provides several graphical "blocks" that you can combine to create graphical user interfaces without having to build them from scratch yourself. These include elements such as plots, tables, user-input fields, toolbars, grids and tabs. These all derive from the JFXWindow class thus they all share some common basic functionality.

This page serves as a guide on this shared functionality including window control (opening, closing, maximising etc), creating layouts and defining what happens when the user closes a window.

Opening and Closing Windows

All GUI elements can be shown separately in their own window. After creating such an element, for example a Table, we can make it show-up in its own window by use of show() like so:

Table window = new Table("Title");
window.show();

This results in

You can then make it close by use of:

window.close();

or just to quickly hide it (it the window closes but is kept in memory):

window.hide();

Extra Window Features

Sometimes, you may wish for your window to maximise, to do this you can use the setMaximised(...) method like so:

window.setMaximised(true);  // This will make the window maximised
window.setMaximised(false); // This will un-maximise the window

Aditionally, if a window is the "main" window then you might want it to terminate the program if closed. To set this use setExitOnClose(...) like so:

window.setExitOnClose(true);  // Terminates execution when window is closed
window.setExitOnClose(false); // Does not terminate when closed

Containers

Some GUI elements act as "containers". That is they exist to hold other GUI elements together in a single window. These elements implement the Container interface as well as being subclasses of JFXWindow, so they provide all the same common functionality as any other GUI element, but with some additions.

To look at this, let's start by creating an example:

Plot  plot      = new Plot("My Plot", "X", "Y");
Table table     = new Table("My Table");

// Grid is a "container" that displays elements in a grid
Grid  container = new Grid("My Grid");

So we now have a Plot element and a Table element as well as our container, which is a Grid in this case.

We can add elements, one at a time, to a container by use of add(...) like so:

container.add(plot);
container.add(table);

alternatively you can add multiple elements at once by use of addAll(...):

container.addAll(plot, table);

Either way, when we show call show() on the container:

container.show();

we get this:

You can also remove an element from a container by specifying the element like so:

container.remove(elementToRemove);

or multiple elements like this:

container.removeAll(elementToRemove1, elementToRemove2, elementToRemove3); // etc

You can also remove all elements by use of:

container.clear();

Clone this wiki locally