这样的事情不工作吗?
AnchorPane main=new AnchorPane();
AnchorPane sub1=new AnchorPane();
sub1.getChildren().add(btn);
main.getChildren().add(sub1);
当你想切换布局时
AnchorPane sub2=new AnchorPane();
main.getChildren().remove(sub1);
main.getChildren().add(sub2);
编辑
我想我错过了你是如何做布局的。这就是我的设想。
Definitions to Various Components
MainLayout
-> CustomLayout 1
-> References to various components. ( Essentially you are not creating all the components for every layout, rather you are referring to them in each layout )
-> CustomLayout 2
-> References to various components. ( More or less a different arrangement of the same components, adds some component references and removes some )
-> CustomLayout 3
-> References to various components.
做一个大胆的声明,但如果 JavaFX 中有一个工具,它会如何自动执行此操作?每个模板都需要知道它应该在哪里呈现特定组件,并且可以说最简单的方法就是创建一个新模板,将组件安排在不同的布局中,并在用户想要查看不同的布局时交换模板。