How to add a mouse doubleclick event listener to the cells of a ListView in javafx?


Question

I have a list of links in a ListView. I want to add an mouseEventListener to each cell of the list so that whenever a user double clicks the list item link is opened. I can write the functionality of opening the link on my own but I am not able to add the doubleclick event with every cell in the list. Please help...

1
11
3/20/2014 6:29:22 PM

Let us consider your ListView as playList. Now you can implement the mouse listener with double click functionality on each cell using

playList.setOnMouseClicked(new EventHandler<MouseEvent>() {

    @Override
    public void handle(MouseEvent click) {

        if (click.getClickCount() == 2) {
           //Use ListView's getSelected Item
           currentItemSelected = playList.getSelectionModel()
                                                    .getSelectedItem();
           //use this to do whatever you want to. Open Link etc.
        }
    }
}
25
3/21/2014 2:53:52 AM

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