I modify a ListView with the results from a database search in order to use that selection to make another DB request later on.
I want to get the field
You can make a custom event handler, first make a class to handle mouse events.
import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;
class ListViewHandler implements EventHandler {
@Override
public void handle(MouseEvent event) {
//this method will be overrided in next step
}
}
After making the class, go to where you want the event to happen
list.setOnMouseClicked(new ListViewHandler(){
@Override
public void handle(javafx.scene.input.MouseEvent event) {
System.out.print(list.getSelectionModel().getSelectedIndex());
}
});