1-11. Creating and Working with Observable Lists

Problem

You want to create a GUI application containing two list view controls allowing the user pass items between the two lists.

Solution

Take advantage of JavaFX’s javafx.collections.ObservableList and javafx.scene.control.ListView classes to provide a model-view-controller (MVC) mechanism that updates the UI’s list view control whenever the back-end list is manipulated.

The following code creates a GUI application containing two lists that allow the user to send items contained in one list to be sent to the other. Here you will create a contrived application to pick candidates to be considered heroes. The user will pick potential candidates from the list on the left to be moved into the list ...

Get JavaFX 2.0: Introduction by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.