【问题标题】:Button is "selected" when starting JavaFX program启动 JavaFX 程序时“选择”按钮
【发布时间】:2017-07-15 14:53:16
【问题描述】:

当我运行我的 JavaFX 程序时,我的第一个按钮总是处于选中状态(见周围的蓝线):picture form start
当我使用箭头键将播放器选项设置为向左或向右时,将选择向左或向右按​​钮:
after I pressed right arrow
如何在不选择任何按钮的情况下运行程序

【问题讨论】:

  • 我们可以看看你的场景创建代码吗?

标签: java button javafx-8


【解决方案1】:

展示完舞台后添加root.requestFocus()

    public static void start(Stage stage)
    {
        try 
        {   FXMLLoader loader = new 
                FXMLLoader(StartMain.class.getResource("start.fxml"));
            Parent root = loader.load();
            StartCompanion companion = loader.getController();
            Scene scene = new Scene(root);
            scene.setOnKeyPressed(companion::behandelSpeler);
            scene.setOnMouseClicked(companion::mouseClick);
            stage.setScene(scene);
            stage.show();
            root.requestFocus();
       }
       catch (IOException ex)
       {
                MyError.show("Fout bij opstarten van applicatie");
       }
    }

【讨论】:

  • 谢谢!有效 :D 你能解释一下这是做什么的吗?我在图书馆里查了一下,但对我来说不是那么清楚。
  • 它只是让焦点转到场景的root
猜你喜欢
  • 1970-01-01
  • 2016-04-19
  • 1970-01-01
  • 2021-12-05
  • 1970-01-01
  • 2021-03-27
  • 1970-01-01
  • 1970-01-01
  • 2016-10-06
相关资源
最近更新 更多