当其他应用在javafx中单击时,停止全屏窗口返回

当其他应用在javafx中单击时,停止全屏窗口返回,java,javafx,Java,Javafx,好的,我正在尝试使用JavaFx制作一个应用程序,它在全屏的第二个屏幕上显示当前正在播放的歌曲,而我使用另一个屏幕来做工作。类似 不管怎样,当我在全屏上运行时,一切都很好,但一旦我将其切换到后面,就像在该屏幕上打开的所有其他应用程序后面启动#toBack()函数一样。我试图通过向focusProperty添加ChangeListener来避免这种情况: stage.focusedProperty().addListener((observable, oldValue, newValue) -&g

好的,我正在尝试使用JavaFx制作一个应用程序,它在全屏的第二个屏幕上显示当前正在播放的歌曲,而我使用另一个屏幕来做工作。类似 不管怎样,当我在全屏上运行时,一切都很好,但一旦我将其切换到后面,就像在该屏幕上打开的所有其他应用程序后面启动#toBack()函数一样。我试图通过向focusProperty添加ChangeListener来避免这种情况:

stage.focusedProperty().addListener((observable, oldValue, newValue) -> {
        if(oldValue) Platform.runLater(() -> {
            stage.toFront();
            stage.setAlwaysOnTop(false);
        });
    });
然后一切都很好,当我使用另一个屏幕时,它会保持在前面,但当我尝试在屏幕上显示另一个应用程序时,我的全屏显示正在运行,我的应用程序会保持在前面,无论如何,这不是因为添加到focusProperty的ChangeListener,它的行为就像它将被设置为“始终在顶部”

我的问题:如何让应用程序保持全屏状态,但在失去焦点时不返回屏幕后部,同时也不让它始终处于顶部


谢谢您的帮助。@kleopatra,更新了,抱歉给您带来麻烦,我是新来的
public class Main extends Application {

   @Override
   public void start(Stage primaryStage) throws Exception{
       Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
       primaryStage.setTitle("Hello World");
       primaryStage.setScene(new Scene(root, 300, 275));

       primaryStage.setFullScreen(true);
       

       primaryStage.focusedProperty().addListener((observable, oldValue, newValue) -> {
           if(oldValue) {
               System.out.println("Fired");
               Platform.runLater(() ->  primaryStage.toFront());
               primaryStage.setAlwaysOnTop(false);
           }
       });

       primaryStage.getScene().setOnKeyPressed(event -> {
           if(event.getCode() == KeyCode.F11) {
               primaryStage.setFullScreen(!primaryStage.isFullScreen());
           }
       });


       primaryStage.show();
   }


   public static void main(String[] args) {
       launch(args);
   }
}
    <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>


<GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/15.0.1" fx:controller="sample.Controller">
   <columnConstraints>
      <ColumnConstraints />
   </columnConstraints>
   <rowConstraints>
      <RowConstraints />
   </rowConstraints>
   <children>
      <AnchorPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: rgb(100,200,100);" />
   </children>
</GridPane>
public class Controller {
}