1

I'm using the ControlsFX ToggleSwitch like so:

<ToggleSwitch fx:id="toggle" onAction="#handleToggleAction" mnemonicParsing="false" GridPane.columnIndex="1" /> 

I want to be able to associate actions on this ToggleSwitch with a method in my controller.

This is some of my code in the controller:

@FXML private void handleToggleAction(ActionEvent event) throws IOException { Boolean selected = ((ToggleSwitch) event.getSource()).isSelected(); if(selected) { //do something } else { //something else } } 

This is causing me an error:

Cannot determine type for property. 

I don't know why this is causing an error. Before using a ToggleSwitch I was using a ToggleButton and the handler method was working fine. Any help appreciated.

1 Answer 1

4

ToggleSwitch simply does not contain a onAction property.

Therefore it's probably best to register a listener in the initialize method of the controller:

@FXML private void initialize() { toggle.selectedProperty().addListener((observable, oldValue, newValue) -> { if(newValue) { //do something } else { //something else } }); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.