Considering the following sample.
How to access to arguments/parameters of the application in the controller?
Thank you.
1. Most straightforward way -- save them in app:
public class App extends Application {
public static void main(String[] args) { launch(); }
public static String parameters;
@Override
public void start(Stage primaryStage) throws Exception {
parameters = getParameters().getNamed().toString();
Parent root = FXMLLoader.load(getClass().getResource("MyView.fxml"));
final Scene scene = new javafx.scene.Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
}
and read them in controller:
public class MyController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println(App.parameters);
}
2. More complex (but better in general) approaches are described in next topics: