How to create multiple javafx controllers with different fxml files?

Use FXML as components by using a custom java class as fx:root and as fx:controller of your FXML file: http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm To do so, you need to call in the constructor of your custom java class FXMLLoader which will load your FXML. The advantage is to change the way FXML load components. The classic way to … Read more

Using JavaFX controller without FXML

Your question isn’t particularly clear to me: you just create the classes and basically tie everything together with listeners. I don’t know if this helps, but here is a simple example that just has a couple of text fields and a label displaying their sum. This is what I regard as “classical MVC”: the view … Read more

Have multiple FXML files (created in SceneBuilder), but only one controller. Does each scene load it’s own copy of the controller?

Your controller file is a Java source file which gets compiled to a single Java class from which many Java object instances may be created. At runtime the default fxml loader controller factory implementation will create a new controller instance (i.e. a new object), every time you invoke the fxml loader’s load method. Even if … Read more

JavaFX: Change application language on the run

You can do something like this. As in your answer, you would either want to implement this as a singleton, or use a DI framework to inject a single instance wherever you need it: public class ObservableResourceFactory { private ObjectProperty<ResourceBundle> resources = new SimpleObjectProperty<>(); public ObjectProperty<ResourceBundle> resourcesProperty() { return resources ; } public final ResourceBundle … Read more

How to switch scenes in JavaFX

I wrote this controller to keep track of the different scenegraphes. public class ScreenController { private HashMap<String, Pane> screenMap = new HashMap<>(); private Scene main; public ScreenController(Scene main) { this.main = main; } protected void addScreen(String name, Pane pane){ screenMap.put(name, pane); } protected void removeScreen(String name){ screenMap.remove(name); } protected void activate(String name){ main.setRoot( screenMap.get(name) ); … Read more

Styling a JavaFX 2 button using FXML only – How to add an image to a button?

Solution using only fxml As tarrsalah points out, css is the recommended way of doing this, though you can also do it in fxml if you prefer: <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.control.*?> <?import javafx.scene.image.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.text.*?> <AnchorPane id=”AnchorPane” maxHeight=”-Infinity” maxWidth=”-Infinity” minHeight=”-Infinity” minWidth=”-Infinity” prefHeight=”400.0″ prefWidth=”600.0″ xmlns:fx=”http://javafx.com/fxml”> <children> <Button layoutX=”104.0″ layoutY=”81.0″ mnemonicParsing=”false” … Read more

Cant create new FXML File in Eclipse

It looks like e(fx)clipse hasn’t been updated for 2022-12, which removed some DataBinding APIs. You can open an issue at https://github.com/eclipse-efx/efxclipse-eclipse/issues, but if you can work up a pull request to fix it, that’ll probably move things along far more quickly.