我想要一个选项来切换alwaysontop
true/false。但是,当我关闭并显示窗口时,它不会接管它。
@FXML
public void toggleAlwaysonTop(ActionEvent event){
try{
Worker.toggleAlwaysOnTop(); //changes boolean if it is always on top and saves it log
Stage stage = (Stage) ((Node)event.getSource()).getScene().getWindow(); //gets stage of settings window
Stage changer = Application.getPrimaryStage(); //gets primary stage of the Application
stage.close();
changer.close();
changer.show();
}catch (Exception e) {
System.out.println("Error bei der App Klicken von ModeButton. n error is: "+e);
e.printStackTrace();
}
}
在Application
类中我使用:
primaryStage.setAlwaysOnTop(Worker.isItalwaysOnTop);
对于第二个窗口,当我通过按钮再次打开它时,它是否工作。但是如果我用stage.close()
和stage.show()
我有同样的问题。我使用类似的方法在暗/亮模式之间切换。这里它工作得很好。
哦,这其实很简单,你只需要使用stage.setAlwaysOnTop();
和changer.requestFocus();
(直接接管)
@FXML
public void toggleAlwaysonTop(ActionEvent event){
try{
Worker.toggleAlwaysOnTop(); //changes boolean if it is always on top and saves it log
Stage stage = (Stage) ((Node)event.getSource()).getScene().getWindow(); //gets stage of settings window
Stage changer = Application.getPrimaryStage(); //gets primary stage of the Application
stage.close();
changer.setAlwaysOnTop(Worker.isItalwaysOnTop);
changer.requestFocus();//Preventing that it does not take it over directly when you worked in another application before (sry I can't explain the Problem properly^^)
}catch (Exception e) {
System.out.println("Error bei der App Klicken von ModeButton. n error is: "+e);
e.printStackTrace();
}
}