I am invoking a JavaFX application from java.I want to use the String arguments in that JavaFX application. How to get that parameters in ChatWithSpecificClient?
For example :
Invoking Class
public class GenWindow{
public static void main(String[] args) {
Application.launch(ChatWithSpecificClient.class, "String arg");
}
}
Invoked Class
public class ChatWithSpecificClient extends Application {
private Parent createScene() {
BorderPane pane = new BorderPane();
return pane;
}
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(createScene());
primaryStage.setScene(scene);
primaryStage.show();
}
}
For instance, How to set the title of this window to that argument?
By using getRaw()
method of the Parameters class, you can get a String list of arguments passed to the launch method
of Application class. For example if you, invoke the application as.
Application.launch(ChatWithSpecificClient.class, "Client's name", "email");
Then at the end of the start(Stage s)
method of your class get these values as a String list.
Parameters params = getParameters();
List<String> list = params.getRaw();
System.out.println(list.size());
for(String each : list){
System.out.println(each);
}
From the documentation:
args - the command line arguments passed to the application. An application may get these parameters using the getParameters() method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With