1 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個贊
在主控制器中:
public class MainController {
/**
* var name has to be topController
*/
public TopController topController;
/**
* var name has to be bottomController
*/
public BottomController bottomController;
public void initialize(){
Button topbtn=topController.topbtn;
Button bottombtn=bottomController.bottombtn;
topbtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello from top button");
topbtn.setDisable(true); //OK!
bottombtn.setDisable(false); //Failed
}
});
}
}
底部.fxml:
<VBox fx:id="vbox" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="BottomController">
<children>
<Button fx:id="bottombtn" text="OK" />
</children>
</VBox>
頂部.fxml:
<VBox fx:id="vbox" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="TopController">
<children>
<Button fx:id="topbtn" text="OK" />
</children>
</VBox>
并在 TopController 和 BottomController 類中設(shè)置 @FXML public Button **btnName**;
底部控制器:
public class BottomController {
public Button bottombtn;
}
頂級控制器:
public class TopController {
public Button topbtn;
}
另一個 用于設(shè)置topController值initialize的選項(xiàng)MainControllerbottombtn
添加回答
舉報(bào)