Reputation: 687
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?
Upvotes: 10
Views: 8959
Reputation: 7324
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);
}
Upvotes: 15
Reputation: 6911
From the documentation:
args - the command line arguments passed to the application. An application may get these parameters using the getParameters() method.
Upvotes: 2