Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding RadioMenuItem to ToggleGroup in FXML

Somewhere inside my FXML, I have this:

<fx:define>
  <ToggleGroup fx:id="toggleGroup1"/>  
</fx:define>
<Menu fx:id="toggleMyView" text="%MyView">
  <items>
    <RadioMenuItem text="%hide"
                   selected="true"
                   onAction="#handleLoadComponent"
                   toggleGroup="toggleGroup1"/>`

Somehow I get the error:

Unable to coerce toggleGroup1 to class javafx.scene.control.ToggleGroup

But why?

What I'm trying to do is to create a Menu containing several of RadioMenuItem which are all in the same ToggleGroup. How can I add them to the toggle group in my FXML file?

like image 682
spilot Avatar asked Dec 01 '15 00:12

spilot


2 Answers

You have to write

toggleGroup="$toggleGroup1"
like image 200
spilot Avatar answered Oct 24 '22 10:10

spilot


If you are using SceneBuilder then set the field ToggleGroup in properties to the name of the group.

like image 30
user9521908 Avatar answered Oct 24 '22 10:10

user9521908