I took a quick look at this blog / tutorial https://www.pragmaticcoding.ca/javafx/swap-scenes
but it shows the UI in Java and im using FXML, how would i make the java UI part with FXML?
#How to swap scenes properly using FXML - JavaFX
1 messages · Page 1 of 1 (latest)
<@&987246487241105418> please have a look, thanks.
interesting approach, but I would do it differently
to answer your question:
but it shows the UI in Java and im using FXML, how would i make the java UI part with FXML?
this is the point that uses java instead of fxml:
final Scene scene1 = new Scene(new VBox());
final Scene scene2 = new Scene(new VBox());
instead of simply doing new Scene you just use fxmlloader to load the scene
but well it wont work with the implementation
like the setRoot call wont work as you would want it
I havent touched this apart from the name and the size, but this is the default method for the stage
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("/view/SettingsView.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 240, 80);
stage.setTitle("Pomodoro Timer");
stage.setScene(scene);
stage.show();
}
I am really interested in answering your question, including the mvc questions, but I simply dont have the time right now
there is some stuff you would need to change in the code to make it work for fxml files
and therefore you kinda need to understand what its actually doing
like you dont need two classes Layout1Builder and Layout2Builder
with fxml you would just need one
which loads the fxml in the build() call
i closed the MVC questions since i figured those out, which was a FXML issue on my end
would you need/want 2 FXML files
or preferable just 1 FXML file for both scenes?
2 fxml
but the builder got the same logic for both, just for different files
so you dont need to define two builder
but as I said I would initially do it differently
but there are many ways
i might as well just make the 2 scenes and them see how i could combine them
or switch between them
public class FxmlBuilder implements Builder<Region> {
private final String file;
private final Runnable sceneSwapper;
public FxmlBuilder(String file, Runnable sceneSwapper) { // might want to use a different type for the filename
this.file = file;
this.sceneSwapper = sceneSwapper;
}
@Override
public Region build() {
// load fxml using the file name, get the button and set the on action, then return the region returned by it
return ...;
}
}
something like that
so this would be the scenemanager or just only the FXML builder?
this is just the Layout1Builder, but for fxml files in general with the intention to have swapping scenes abilities
i got no idea what this all means
well therefore you need to know java
what exactly isnt clear for you?
do you know what a class is? a constructor? implementing an interface? overriding methods?
its an interface that javafx provides
javafx.util.Builder<T>
but you dont need it tbh
oowh is that the scene builder?
for your usage the class will work fine like this:
public class FxmlBuilder {
private final String file;
private final Runnable sceneSwapper;
public FxmlBuilder(String file, Runnable sceneSwapper) { // might want to use a different type for the filename
this.file = file;
this.sceneSwapper = sceneSwapper;
}
public Region build() {
// load fxml using the file name, get the button and set the on action, then return the region returned by it
return ...;
}
}
no, not related at all
its just an interface
but you dont take advantage of the FxmlBuilder being a subclass of it, so you dont need it