答案 0 :(得分:2)
单独使用SceneBuilder无法做到这一点,但可以通过自己编辑fxml来完成。只需使用ToggleButton
开启/关闭按钮,然后将disable
属性绑定到selected
的{{1}}属性,或者在ToggleButton
方法中执行此操作控制器(要求所有initialize
通过Button
注入控制器。
fx:id
控制器中的<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.*?>
<VBox xmlns:fx="http://javafx.com/fxml/1" spacing="10">
<padding>
<Insets left="10" right="10" bottom="10" top="10" />
</padding>
<children>
<fx:define>
<!-- create ToggleButton to be used with the disable properties -->
<ToggleButton fx:id="on" text="On"/>
</fx:define>
<!-- create buttons and bind the disable property to the negated
selected property of the on button -->
<Button text="Button 1" disable="${!on.selected}" />
<Button text="Button 2" disable="${!on.selected}" />
<Button text="Button 3" disable="${!on.selected}" />
<Button text="Button 4" disable="${!on.selected}" />
<Button text="Button 5" disable="${!on.selected}" />
<!-- add on button to scene -->
<fx:reference source="on"/>
</children>
</VBox>
答案 1 :(得分:0)
为了快速做到这一点,我建议你添加所有按钮,除了打开/关闭一个容器,如hbox v盒或你想要的容器,然后禁用包含你的按钮的容器(父),例如
vBoxMain.getChildren().addAll(/*every button except on/off*/);
//or generate dynamically the buttons and add them to the vBoxMain in a for cycle
buttonOnOff.setOnAction((ActionEvent e) -> {
if(vBoxMain.isDidable()){
vBoxMain.setDisable(false);
}else{
vBoxMain.setDisable(true);
}
});
这不是针对您的具体布局,而是为了给您一个想法,我希望它会对您有所帮助。