I have a ComboBox. And this combobox has items=ObservableList<Test>
. In order to work with object Test I set cell factory for combobox:combobox.setCellFactory(...)
. Class Test is the following:
public class Test{
private Integer id;
private String name;
//+getters and setters
}
Questions:
- How can I make combobox set selected Test with id=X (list of Tests is already added to combobox)?
- How can I get currently selected Test?
With
ComboBox<Test> combo
:1)
combo.getSelectionModel().select( X );
where X is an index ofTest
2)
combo.getSelectionModel().getSelectedItem();
returns theTest