vendredi 2 décembre 2016

How to detect click on JavaFX CheckBox item

I have a very simple question: There is a CheckBox with some elements. I can click and choose one of them. A also have a selection listner, which works as expected if I change the selected element. Now I need to perform an action ALWAYS if I click (or enter witah a keyboard) on ONE of check box elements. Sure it works in selection listner, but (!) if an element "XYZ" is selected already and I click on it AGAIN (the action must be performed) nothing happens (and actually it's expected behavior). How can I get this event?

The first Idea is to use "setOnHiddenProperty", something like

myChoiceBox.onHiddenProperty().set((EventHandler<Event>) (Event event) -> {
  //Check which element is currently selected and perform an action if it's "XYZ"
});

But it doesn't works:( I think it's just any mistake here probably... I have tried just an ActionListner, which schould works always

myChoiceBox.setOnAction((ActionEvent event) -> {
    // --*--
});

But he works only if new Item has been chosen (as selection listner) ind not if I click it again.

Any advices? Thanks!




Aucun commentaire:

Enregistrer un commentaire