Using command line arguments in Java with JavaFX

前端 未结 1 1835
借酒劲吻你
借酒劲吻你 2021-01-11 12:21

I have the following code:

public class Main extends Application {

  @Override
  public void start(Stage primaryStage) throws Exception{
      Parent root =         


        
相关标签:
1条回答
  • 2021-01-11 12:54

    Try getParameters. This should give you the command line arguments

    As wished a small example (i took the main code from Raphael's answer)

    Assuming the controller class is named "MyController"

    public class Main extends Application {
    
     @Override
     public void start(Stage primaryStage) throws Exception{
    
        FXMLLoader loader=new FXMLLoader(getClass().getResource("hive.fxml"));
        Parent root = loader.load();
        MyController cont=load.getController();
        /*
          This depends on your controller and you have to decide 
          How your controller need the arguments
        */
        cont.setParameter(getParameters()); 
    
        primaryStage.setTitle("Hive-viewer");
        primaryStage.setScene(new Scene(root, 1600, 900));
        primaryStage.show();
     }
    
    
     public static void main(String[] args) {
        launch(args);
     }
    }
    
    0 讨论(0)
提交回复
热议问题