JavaFx 场景构建器可以用来创建 Java 代码而不是 FXML [英] Can JavaFx scenebuilder used to create Java Code instead of FXML

查看:103
本文介绍了JavaFx 场景构建器可以用来创建 Java 代码而不是 FXML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Javafx 的初学者.我发现 Javafx Scene builder 非常适合生成与 Javafx 相关的任何表单,但它只使用 fxml 文件而不是 java文件.

I'm a beginner in Javafx. I found that Javafx Scene builder is pretty cool to generate any forms related to Javafx, but it does play with only fxml files and not with java files.

例如:当我使用 Scene Builder 创建 MenuListItems 等时,它只生成具有类似 html 文件的源(XML 输出).

For e.g: When I create MenuList, Items etc. using Scene Builder it just generates the source with similar html files only (XML output).

但我不想限制使用这些 XML 文件.那么有没有人知道在不使用 fxml 的情况下处理 java 文件 的个人技术?

But I do not want to confine with the use of these XML files. So does anyone knows the individual technique to handle along java file without using fxml ?

提前致谢!

推荐答案

问题的答案 JavaFx 场景生成器能否用于创建 Java 代码而不是 FXML你不能

如果您需要使用Java 来创建您的表示层,您将不得不通过自己编写代码来完成,这是有原因的.请关注以下帖子:

If you need to use Java to create your Presentation Layer, you will have to do it by writing codes on your own and there are reasons to it. Please follow the post below :

JavaFX 使您能够使用 Java 代码和名为 FXML 的基于 XML 的语言创建 UI.引入了 Scene Builder 以利用 FXML 的使用,通过提供 DRAG n DROP 功能来生成 FXML 代码.您可以认为这类似于 Window Builder for Swing,不同之处在于最终结果在 FXML(.fxml) 而不是 Java(.java).

JavaFX empowers you to create UI using both Java code and XML-based language called FXML. Scene Builder was introduced to leverage the use of FXML, by providing a DRAG n DROP feature, to generate FXML code. You can consider this similar to Window Builder for Swing, with a difference of the end result being in FXML(.fxml) instead of Java(.java).

黑白 Java 代码和 FXML 的基本区别

Java 代码

BorderPane border = new BorderPane();
Label toppanetext = new Label("Page Title");
border.setTop(toppanetext);
Label centerpanetext = new Label ("Some data here");
border.setCenter(centerpanetext);

FXML

<BorderPane>
    <top>
        <Label text="Page Title"/>
    </top>
    <center>
        <Label text="Some data here"/>
    </center>
</BorderPane>

为什么要使用 FXML,当我可以通过 JAVA 代码实现相同的功能时

您可能会想为什么要使用 FXML,而我们可以使用 JAVA 来做同样的事情.好吧,这是你的选择!!

You would be thinking as to why to use FXML, when we can make the same using JAVA. Well, its your choice !!

来自文档

FXML 是一种基于 XML 的语言,它提供了用于构建与代码的应用程序逻辑分离的用户界面.这种表现和应用逻辑的分离是对 Web 开发人员有吸引力,因为他们可以聚集用户无需掌握代码即可利用 Java 组件的接口用于获取和填充数据

FXML is an XML-based language that provides the structure for building a user interface separate from the application logic of your code. This separation of the presentation and application logic is attractive to web developers because they can assemble a user interface that leverages Java components without mastering the code for fetching and filling in the data

因此,FXML 强制您使用 MVC 模式,将表示层与逻辑分开,使您更容易维护和编辑表示层,并且通过与 Java/JavaFX 无关的 UI 设计人员

So, FXML forces you to use a MVC pattern, keeping your presentation layer separate from the logic, making it easier for you to maintain and edit the presentation layer, and through UI designers, who have no relation to Java/JavaFX

有关 FXML 的更多信息和示例

这篇关于JavaFx 场景构建器可以用来创建 Java 代码而不是 FXML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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