简体   繁体   English

默认情况下,JavaFX在哪里创建FXML文件?

[英]Where does JavaFX create the FXML file by default?

EDIT: Changed the question for clarity 编辑:为清楚起见更改了问题

Where do JavaFX application store the FXML by default? 默认情况下,JavaFX应用程序在哪里存储FXML? Do they create an FXML file, and where is it put if they do? 他们是否创建FXML文件,如果这样做,该文件放在哪里? Can I specify a place for the FXML to be compiled to? 是否可以为FXML指定编译位置? I'd like to edit the FXML directly, but I've written the GUI instructions into my main Java application (I'm a novice and this is just how I learned to do it). 我想直接编辑FXML,但是我已经将GUI指令写到了我的主要Java应用程序中(我是新手,这就是我学会的方法)。 I'm using Eclipse, if that matters. 如果这很重要,我正在使用Eclipse。

JavaFX code does not generate FXML files. JavaFX代码不会生成FXML文件。 A hand-written JavaFX application will not use FXML and will not generate FXML. 手写JavaFX应用程序将不使用FXML,也不会生成FXML。 If you hand-write JavaFX code to define a scene graph then you are creating an object tree and this all stays in memory just like any other data held in objects (unless you go out of your way to write some object serialization process to write parts of your application state to disk). 如果您手工编写JavaFX代码来定义场景图,那么您正在创建一个对象树,并且所有这些对象都将保留在内存中,就像对象中保存的任何其他数据一样(除非您不愿意编写一些对象序列化过程来编写部件)您的应用程序状态到磁盘)。

FXML files are just XML documents which offer an alternative way to describe a scene graph. FXML文件只是XML文档,它提供了一种描述场景图的替代方法。 And the best way to edit FXML files is using Scene Builder which is dedicated to this purpose. 而编辑FXML文件的最佳方法是使用专用于此目的的Scene Builder The idea is that this approach allows a non-developer to create and tweak the structure of a JavaFX scene, because you can use drag-and-drop and property navigators to quickly create any scene without writing a single line of code. 想法是,这种方法允许非开发人员创建和调整JavaFX场景的结构,因为您可以使用拖放和属性导航器快速创建任何场景,而无需编写任何代码。 Even as a developer I think that the FXML approach is far more elegant and faster than trying to write the scene graph code by hand. 即使是开发人员,我也认为FXML方法比尝试手动编写场景图代码要优雅得多,而且速度更快。

It takes a bit of effort to grasp the FXML approach but I reckon it's worth the time if you're going to creating anything but the simplest scenes. 掌握FXML方法需要花费一些精力,但是如果您要创建除最简单的场景之外的任何内容,我认为这是值得的。 I learned how to load FXML files into a JavaFX application from the book Learn JavaFX 8 by Sharan, but you can probably gather the same knowledge from online tutorials such as Oracle's Introduction to FXML . 我从Sharan的《 学习JavaFX 8 》一书中学习了如何将FXML文件加载到JavaFX应用程序中,但是您可能可以从在线教程(例如Oracle的FXML简介)中获得相同的知识。 (Be aware that the latest version of JavaFX is 12, but the advice about version 8 still largely applies.) (请注意,JavaFX的最新版本是12,但是有关版本8的建议仍然适用。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM