I want to make RadioButtons in the application that change the picture on the screen. I can not understand how to get information about clicking on them.

So I created them and assigned information about them:

ToggleGroup group = new ToggleGroup(); // Группа для RadioButton'ов RadioButton rb1 = new RadioButton("Home"); RadioButton rb2 = new RadioButton("Work"); RadioButton rb3 = new RadioButton("Rest"); rb1.setToggleGroup(group); rb2.setToggleGroup(group); rb3.setToggleGroup(group); rb1.setUserData("Home"); rb2.setUserData("Work"); rb3.setUserData("Rest"); 

After that, I try to read information about the choice of the desired RadioButton:

  group.selectedToggleProperty().addListener(event -> { System.out.println(this.getClass().getResourceAsStream(group.getSelectedToggle().getUserData() + ".png")); }); 

The console displays null when any RadioButton is clicked.

All program listing is here .

  • And the output to the console group.getSelectedToggle (). GetUserData () + .png does everything output normally? - Andrew Bystrov
  • Most likely, getResourceAsStream does not find files (they are not found anywhere on the githaba). If getSelectedToggle returned null , everything would fall. - zRrr
  • I created the project under Maven, but not JavaFx. There is a possibility that something is missing from the project. - faoxis

0