I have my JavaFX 2.0 application, where i need to make some action, after user clicked an item in ListView element. To construct user GUI i\'m using FXML, in which i have so
A simple fix to Sergey's answer, without having to create a whole new listCell (in your case you do, but we don't have to in a regular text case).
all you need to simply do is create a temp variable that is equal to the first list item at first, and that gets changed to each new clicked item. Once you try to click the item again, the temp variable knows it's the same, and with an if statement you can get around that.
temp Item is a global that you put up top String tempItem = "admin";
for me I knew my first field is always going to be labeled "admin" so I set it as such. you would have to get the first entry and set it outside of the method you are going to use for list selecting.
private void selUser() throws IOException
{
String item = userList.getSelectionModel().getSelectedItem().toString();
if(item != tempItem)
{
//click, do something
}
tempItem = item;
}
As for me I used an FXML document that called my method
@FXML
public void userSel(MouseEvent mouse) throws IOException
{
selUser();
}
In this case you could just take the entire contents of the selUser() method and put it into the userSel mouse click.