Skip to content

GUI Elements

William Wood edited this page Jun 2, 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 are called "elements" and include 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.

Contents

  1. Opening and Closing Windows
  2. Extra Window Features
  3. Containers
  4. JFXWindow/Element Method Reference
  5. Container Method Reference

Opening and Closing Windows

Top ↑

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 closes the window but keeps it in memory):

window.hide();

Extra Window Features

Top ↑

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

Top ↑

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();

JFXWindow/Element Reference

Top ↑

Method Description
window.show();
Makes the GUI element show itself in its own window.
window.hide();
Make the open window close whilst remaining active in memory.
window.close();
Makes the GUI element close and remove itself from memory.
window.setMaximised(boolean max);
Sets whether the window is maximised or not.
window.close();
Makes the GUI element close and remove itself from memory.
window.setExitOnClose(boolean exit);
Sets whether the program should terminate when this window is closed.

Container Reference

Top ↑

Method Description
container.add(Element e);
Adds the specified GUI element to the container.
container.addAll(Element... e);
Adds all the specified GUI elements to the container in order.
container.addAll(Collection<Element> e);
Adds all the GUI elements in the collection to the container.
container.remove(Element e);
Removes the specified element from the container (if it is present).
container.removeAll(Element... e);
Removes all the specified elements from the container (if present).
container.removeAll(Collection<Element> e);
Removes all the elements in the collection from the container (if present).
container.clear();
Removes all elements from the container.
List<Element> list = container.getElements();
Returns a list of all elements in the container. Changes to this list do not propagate back to the container.
Clone this wiki locally