Views
4 months ago

tornadofx-guide

5. Data Controls The

5. Data Controls The cellCache function receives each item in the list, and since we used a list of Strings in our example, we simply pass that string to the imageview() builder to create an ImageView inside each table cell. It is important to call the cellCache function instead of the cellFormat function to avoid recreating the images every time the DataGrid redraws. It will reuse the items. Let's create a scene graph that is a little bit more involved, and also change the default size of each cell: 68

5. Data Controls val numbers = (1..10).toList() datagrid(numbers) { cellHeight = 75.0 cellWidth = 75.0 multiSelect = true } cellCache { stackpane { circle(radius = 25.0) { fill = Color.FORESTGREEN } label(it.toString()) } } Figure 5.9 The grid is supplied with a list of numbers this time. We start by specifying a cell height and width of 75 pixels, half of the default size. We also configure multi select to be able to select more than a single element. This is a shortcut of writing selectionModel.selectionMode = SelectionMode.MULTIPLE via an extension property. We create a StackPane that stacks a Label on top of a Circle . 69

GUIDE
Guide
Guide
GUIDE
GUIDE
Guide
Guide
GUIDE
Guide
GUIDE
GUIDE
GUIDE