如何替换删除,添加和替换窗格? [英] How to replace Remove, Add and Replace Panes?

查看:305
本文介绍了如何替换删除,添加和替换窗格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JAVA的抽象以某种方式通过允许我们创建一个JFrame (并将其保存在自己的 .JAVA文件中并用不同类型的对象填充它来实现。作为JPanels,JTextFields ... (保存在不同的文件中)如果需要,可以使用remove(),add(),validate(),repaint()方法。

JAVA's abstraction is somehow brought out by allowing us to create a JFrame (and save it in its own .JAVA file) and populate it with different kinds of objects such as JPanels, JTextFields ... (saved in different files) if and when needed by using the remove(), add(), validate(), repaint() methods.

我正在尝试将我的JAVA项目转移到JAVA-FX,因为它通过JavaFX Scene Builder和css在设计方面具有极大的灵活性。这里有相应的上述方法(在JAVA-FX中)吗?有没有办法我可以创建一个窗格或一个标签...并将其保存在自己的文件中,因为它等待用其自己的子节点替换另一个Pane (并保存在自己的文件中) 以后在舞台上通过动作调用时,例如按钮点击?

I'm trying to move my JAVA project to JAVA-FX due its great flexibility in design via JavaFX Scene Builder and css. Are there any equivalents to the above methods here (In JAVA-FX)? Is there a way I could create a Pane or a Label ... and save it in its own file as it waits to replace onother Pane with its own child Nodes (and saved in its own file) on the Stage later when it's called via an action, such as a button click?

非常感谢任何帮助。枚举上述内容的示例代码也有帮助。

Would really appreciate any help. Sample code enumerating the above could help also.

提前全部谢谢。

你的真实,完成JAVA-FX 新手

推荐答案

在常规JavaFX应用程序中,只有一个主要阶段和一个场景。创建包含任何JavaFX节点的FXML文件(可选择使用其控制器),并使用 FXMLoader 在按钮操作上加载此文件。然后你可以使用加载的节点作为场景的根;

scene.setRoot(MYNode)(尽管只有 Parent 可以设置为root)

或将其作为子节点添加到根节点的子树中;
如果您知道子结构,则
scene.getRoot()。getChildren()。get(3).getChildren()。add(MYNode);

如果你知道 id scene.lookup(myPane)。getChildren()。add(MYNode);

In a regular JavaFX application, there is only one primary stage and its one scene. Create your FXML file (optionally with its controller) containing any JavaFX node and load this file on button action using FXMLoader. Then you can use the loaded node as a root of scene;
scene.setRoot(MYNode) (though only Parent can be set as root)
or add it to subtree of root node as a child;
if you know the substructure: scene.getRoot().getChildren().get(3).getChildren().add(MYNode);
if you know the id: scene.lookup("myPane").getChildren().add(MYNode);

同样的逻辑适用于在另一个动作事件中加载的另一个FXML文件。

The same logic applies to another FXML file(s) being loaded in another action event.

这篇关于如何替换删除,添加和替换窗格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆