Java Reference
In-Depth Information
The following code creates a GUI application containing two lists that allow users
to send items contained in one list to the other. Here you will create a contrived applic-
ation to pick candidates to be considered heroes. The user picks potential candidates
from the list on the left to be moved into the list on the right to be considered heroes.
This demonstrates UI list controls' ( ListView ) ability to be synchronized with
backend store lists ( ObservableList ).
public void start(Stage primaryStage) {
primaryStage.setTitle("Chapter 14-10 Creating and
Working with ObservableLists");
Group root = new Group();
Scene scene = new Scene(root, 400, 250, Color.WHITE);
// create a grid pane
GridPane gridpane = new GridPane();
gridpane.setPadding(new Insets(5));
gridpane.setHgap(10);
gridpane.setVgap(10);
// candidates label
Label candidatesLbl = new Label("Candidates");
GridPane.setHalignment(candidatesLbl, HPos.CENTER);
gridpane.add(candidatesLbl, 0, 0);
Label heroesLbl = new Label("Heroes");
gridpane.add(heroesLbl, 2, 0);
GridPane.setHalignment(heroesLbl, HPos.CENTER);
// candidates
final ObservableList<String> candidates
= FXCollections.observableArrayList("Super man",
"Spider man",
"Wolverine",
"Police",
"Fire Rescue",
"Soldiers",
"Dad & Mom",
"Doctor",
Search WWH ::




Custom Search