Java Reference
In-Depth Information
See also
F Chapter 2—Arranging your nodes on stage
F Introduction
Displaying data with the ListView control
In rich GUI frameworks, displaying data in a structured list is one of the fundamental GUI
controls made available to users. In this recipe, we will discuss how to use the ListView
component to collect and display data.
Getting ready
The ListView control is part of the GUI control collection offered by JavaFX in the
javafx.scene.control package. If you have not used the JavaFX controls, it may be
helpful to review the recipe Creating a form with JavaFX controls for some background
information. Some of the code uses JavaFX constructs, such as for-loop expressions.
If you need a refresher, review Chapter 1 , Getting Started with JavaFX, which covers
language fundamentals.
How to do it...
The ListView component has a simple mechanism. You provide it with a sequence of
objects, and it will attempt to display those items in a list. In the next code snippet, we attach
a sequence of String objects to the list to display. You can access the full code listing for this
example from ch04/source-code/src/ListViewDemoSimple.fx .
var w = 400;
var h = 200;
var listView = ListView {
width:w-200
height:h-50
effect:DropShadow{offsetY:3 offsetX:3}
items: for (i in [1..50]) "Cloud {%5s i}"
}
listView.layoutX = (w - listView.width)/2;
listView.layoutY = (h - listView.height)/2;
Stage {
width: w
height: h
 
Search WWH ::




Custom Search