简体   繁体   中英

Where does JavaFX create the FXML file by default?

EDIT: Changed the question for clarity

Where do JavaFX application store the FXML by default? Do they create an FXML file, and where is it put if they do? Can I specify a place for the FXML to be compiled to? 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). I'm using Eclipse, if that matters.

JavaFX code does not generate FXML files. A hand-written JavaFX application will not use FXML and will not generate 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).

FXML files are just XML documents which offer an alternative way to describe a scene graph. And the best way to edit FXML files is using Scene Builder which is dedicated to this purpose. 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. 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.

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. 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 . (Be aware that the latest version of JavaFX is 12, but the advice about version 8 still largely applies.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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