logo
down
shadow

JavaFX: Need help understanding setControllerFactory


JavaFX: Need help understanding setControllerFactory

By : Immanuel Julianto La
Date : October 17 2020, 06:10 PM
this one helps.
I repeatedly came across the method setControllerFactory. Unfortunately I can't find a good explanation for how to use it properly and what it's specific purpose is
code :
FXMLLoader loader = new FXMLLoader(...);
loader.setControllerFactory(c -> {
   return new MyController("foo", "bar");
});
public enum View {
    LOGIN("login/Login.fxml"),
    NEW_USER("register/NewUser.fxml"),
    USER_HOME("user/UserHome.fxml"),
    ADMIN_HOME("admin/AdminHome.fxml");

    public final String location;

    View(String location) {
        this.location = "/views/" + location;
    }
}
public final class MyApp extends Application {

    // Singleton
    private static MyApp singleton;
    public MyApp() { singleton = this; }
    public static MyApp getSingleton() { return singleton; }

    // Main window
    private Stage stage;

    private Map<View, Parent> parents = new HashMap<>();

    @Override
    public void start(Stage primaryStage) {
        stage = primaryStage;
        stage.setTitle("My App");
        add(View.LOGIN);
        stage.setScene(new Scene(parents.get(View.LOGIN)));
        stage.show();
    }

    public void add(View view) {
        var loader = new FXMLLoader(getClass().getResource(view.location));

        try {
            Parent root = loader.load();
            parents.put(view, root);
        } catch (IOException e) { /* Do something */ }
    }

    public void remove(View view) {
        parents.remove(view);
    }

    public void activate(View view) {
        stage.getScene().setRoot(parents.get(view));
    }

    public void removeAllAndActivate(View view) {
        parents.clear();
        add(view);
        activate(view);
    }
}
public final class Login implements Initializable {

    MyApp app = MyApp.getSingleton();

    // Some @FXML variables here..

    @FXML private void login() {
        // Authenticate..
        app.removeAllAndActivate(View.USER_HOME);
    }

    @FXML private void createAccount() {
        app.add(View.NEW_USER);
        app.activate(View.NEW_USER);
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {}
}


Share : facebook icon twitter icon
JavaFX: Need help understanding project hierarchy issues

JavaFX: Need help understanding project hierarchy issues


By : sneha
Date : March 29 2020, 07:55 AM
around this issue My code has gotten quite large and so I've decided to build a runnable JAR to see how it's done. I probably should've tried sooner because I'm getting 2 different errors related to the project structure, first is the "no main manifest attribute error" when trying to run the JAR from command prompt. Double-clicking the JAR does nothing (Win7). The second issue is related to the FXMLLoader explained lower down. , Is my project structure incorrect?
Answer:
JavaFX Intellij error "Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.b

JavaFX Intellij error "Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.b


By : anonymous
Date : March 29 2020, 07:55 AM
this will help to ItachiUchiha for leading me to the answer.
Checking the SDK for my pc revealed that there was no SDK selected. I'm not sure how it was working before.
Understanding Javafx runtime errors

Understanding Javafx runtime errors


By : VitorOliveira
Date : March 29 2020, 07:55 AM
I wish this help you The error is due to wrong image path. To test you code you can use a web resource :
code :
        Image image = new Image("https://candytech.in/wp-content/uploads/2018/04/man-1.png");
        ImageView man = new ImageView(image);
Understanding the JavaFX WebView threading model

Understanding the JavaFX WebView threading model


By : Ajay Gunsola
Date : March 29 2020, 07:55 AM
This might help you Short answer
start() and changed() run from the "JavaFX Application Thread". This thread is responsible for monitoring the UI for events, dispatching them to user code and repainting the UI. Unlike Runnable.run() that when exits, the thread terminates, start() is called by the "JavaFX Application Thread" in something like a loop: when start() ends, the next iteration is executed. (Actually the iterations run asynchronously/wait for events, so as not to eat all CPU resources, but the loop is OK as a simplified model.)
Understanding interpolation method in javafx

Understanding interpolation method in javafx


By : Kiran
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , When the transition runs different values for k will be passed to the interpolate. At the beginning of the animation 0.0 will be passed for k and at the end of the animation 1.0 will be passed.
Related Posts Related Posts :
  • Bad effect on fade in/out transitions when mouse enters or leaves
  • how to make a StylableDoubleProperty editable in scenebuilder
  • Changing values to combobox from an array
  • JavaFX : How to close a sub window without getting focus on main window
  • How to corectly obtain the outer bounds of a node in JavaFX
  • Accessing the Value of a CheckBox in TableView
  • How to add image in a button?
  • Updating two text objects in JavaFX, one field after another, only seeing final result of both changes
  • JavaFX : How to manage the z-index of stages
  • How to display day from selected date using javafx?
  • How can I bind a Label's textFillProperty?
  • derby database open and close connections
  • How to serialize a map that contains Image objects?
  • Creating Custom Control in Jar for Gluon Scene Builder 11.00
  • How to update or change table raw's values in javafx without making the table editable?
  • How can I display all rows of a count query in a javafx textarea? It is only diplaying the first row instead of two rows
  • How to write a function to return a javafx stage
  • How to change textfield inputs to only numbers in javafx?
  • JavaFX: how to read CurrentTime of MediaPlayer while not in JavaFX App Thread
  • Add JavaFX Label - (Using Only Java / JavaFX Code) - To Existing GUI Created With Scenebuilder / FXML
  • JavaFx: about quartz scheduler
  • NullPointerException passing a string from a window to another
  • How to add regex to textfieldtablecell?
  • How to set font for label in JavaFx from root folder?
  • JavaFX 8 count rows in "textarea"
  • Why does prefWidth in javafx takes an argument called height?
  • TreeView scrolling jumps when using large graphic nodes (TornadoFX/JavaFX)
  • Binding LongProperty to internal changes of ListProperty
  • Can't add ImageView to background JavaFX - No fxml
  • Using setStyle to change background color in JavaFx
  • javafx line chart spread out categories along gridlines
  • How to get Key Press working on two file Javafx project
  • fxml: How to handle button action in the controller?
  • Graphic of ButtonCell ComboBox
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk