JavaFx 场景构建器可以用来创建 Java 代码而不是 FXML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25589447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can JavaFx scenebuilder used to create Java Code instead of FXML
提问by nitin sharma
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.
我是 Javafx 的初学者。我发现Javafx Scene builder
生成与 Javafx 相关的任何表单非常酷,但它确实只处理fxml
文件而不是java
文件。
For e.g: When I create MenuList
, Items
etc. using Scene Builder it just generates the source with similar html files only (XML output).
例如:当我使用 Scene Builder创建等时MenuList
,Items
它只生成具有类似 html 文件的源(XML 输出)。
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
?
但我不想confine with the use of these XML files
。那么有没有人知道在java file
不使用的情况下处理的个人技术fxml
?
Thanks in advanced!
先谢谢了!
回答by ItachiUchiha
The answer to your questionCan JavaFx scenebuilder used to create Java Code instead of FXMLis You Can't
您的问题Can JavaFx scenebuilder used to create Java Code 而不是 FXML的答案是You Can't
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 :
如果您需要使用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).
JavaFX 使您能够使用 Java 代码和基于 XML 的语言(称为FXML
. 引入了 Scene Builder 以利用 FXML 的使用,通过提供一项DRAG n DROP
功能来生成 FXML 代码。您可以将其视为类似于Window Builder for Swing,最终结果的不同之处在于 FXML(.fxml) 而不是 Java(.java)。
Basic Difference b/w Java code and FXML
黑白 Java 代码和 FXML 的基本区别
Java Code
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>
Why Use FXML, When I can achive the same via JAVA code
为什么使用 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,当我们可以使用JAVA
. 好吧,它是你的选择!!
From the docs
从文档
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 是一种基于 XML 的语言,它提供了用于构建与代码的应用程序逻辑分离的用户界面的结构。表示和应用程序逻辑的这种分离对 Web 开发人员很有吸引力,因为他们可以组装一个利用 Java 组件的用户界面,而无需掌握用于获取和填充数据的代码
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 强制您使用 MVC 模式,使您的表示层与逻辑分离,使您更容易维护和编辑表示层,并通过与 Java/JavaFX 无关的 UI 设计人员
回答by nejinx
SceneBuilder is for the creation of the gui visually via fxml and does not generate any java code at all. This is left up to the developer.
SceneBuilder 用于通过 fxml 可视化创建 gui,根本不生成任何 java 代码。这由开发人员决定。
A good starting tutorial is here: http://code.makery.ch/java/javafx-2-tutorial-part1/
一个很好的入门教程在这里:http: //code.makery.ch/java/javafx-2-tutorial-part1/
It goes over the use of JavaFX with Eclipse and SceneBuilder
它回顾了 JavaFX 与 Eclipse 和 SceneBuilder 的使用