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 .
getResourceAsStreamdoes not find files (they are not found anywhere on the githaba). IfgetSelectedTogglereturnednull, everything would fall. - zRrr