【发布时间】:2017-05-21 19:20:17
【问题描述】:
伙计们,
很快:我想用 CheckMenuItems(done) 创建 MenuButton。因为我想摆脱复选框,并且我希望 CheckMenuItem 在选中它们后切换(更改颜色),所以我尝试使用 ToggleButtons 进行操作,但我无法将 ToggleButtons/ToggleGroup 放在 MenuButton 内。
感谢您的任何想法。
【问题讨论】:
标签: java javafx togglebutton
伙计们,
很快:我想用 CheckMenuItems(done) 创建 MenuButton。因为我想摆脱复选框,并且我希望 CheckMenuItem 在选中它们后切换(更改颜色),所以我尝试使用 ToggleButtons 进行操作,但我无法将 ToggleButtons/ToggleGroup 放在 MenuButton 内。
感谢您的任何想法。
【问题讨论】:
标签: java javafx togglebutton
即做吧
MenuButton menuButton = new MenuButton("Choices");
ToggleGroup toggleGroup = new ToggleGroup();
RadioMenuItem choice1 = new RadioMenuItem("Choice 1");
RadioMenuItem choice2 = new RadioMenuItem("Choice 2");
choice1.setToggleGroup(toggleGroup);
choice2.setToggleGroup(toggleGroup);
menuButton.getItems().setAll(choice1, choice2);
toggleGroup.selectedToggleProperty().addListener((obs, oldChoice, newChoice) -> {
System.out.println("You chose "+((RadioMenuItem)newChoice).getText());
});
【讨论】: