当我运行 JavaFX 程序时,我的第一个按钮始终处于选中状态(请参见周围的蓝线):picture form start
当我使用箭头键将玩家选择设置为向左或向右时,将选择向左或向右的按钮:
after I pressed right arrow
如何在不选择任何按钮的情况下运行程序
最佳答案
只需在显示舞台后添加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");
}
}
关于java - 启动JavaFX程序时按钮为 "selected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45119511/