JavaFX setting selection in a TableView


Question

How do I set a selection in a TableView? I want the first index selected by default.

productTable.selectionModelProperty().set(value);

Is this right? What should value be?

1
4
1/15/2013 1:05:16 PM

Accepted Answer

The TableViewSelectionModel provides various methods of selections:

productTable.getSelectionModel().selectFirst();

Even the default value should be selected by someone in somewhere. In your case, it is you ;), running above code in some init block.

15
1/15/2013 1:27:04 PM

Generally, TableViewSelectionModel.select(int index) or, if you don't have the index, but you do have the object you want to select handy, TableViewSelectionModel.select(T object). Docs here.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon