如何使JavaFX模态子窗口不显示在alt选项卡中
我有一个JavaFX应用程序,带有一个模式窗口,将主应用程序窗口设置为父窗口。当弹出窗口出现时,我的Ubuntu任务切换程序(alt选项卡)似乎认为这是一个完全不同的窗口;它和主应用程序窗口都显示为选项。如何配置JavaFX,使此窗口不会作为单独的选项显示在alt选项卡中 下面是一个简单的例子:如何使JavaFX模态子窗口不显示在alt选项卡中,java,javafx,Java,Javafx,我有一个JavaFX应用程序,带有一个模式窗口,将主应用程序窗口设置为父窗口。当弹出窗口出现时,我的Ubuntu任务切换程序(alt选项卡)似乎认为这是一个完全不同的窗口;它和主应用程序窗口都显示为选项。如何配置JavaFX,使此窗口不会作为单独的选项显示在alt选项卡中 下面是一个简单的例子: public class PopupExample extends Application { public static void main(String[] args) {
public class PopupExample extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Stage window = new Stage();
window.initOwner(primaryStage);
window.initModality(Modality.APPLICATION_MODAL);
window.show();
}
}
很简单,只需将
StageStyle.UTILITY
设置为第二个Stage
的initStyle
。通过执行此操作,Alt+Tab
将显示一个窗口
以下代码演示了如何处理此问题:
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class PopupExample extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
VBox vBox = new VBox();
vBox.setAlignment(Pos.TOP_CENTER);
Button showPopUpbutton = new Button("Show Stage_TWO");
showPopUpbutton.setOnAction(event -> showPopup());
vBox.getChildren().add(showPopUpbutton);
Scene scene = new Scene(vBox, 300, 300);
primaryStage.setScene(scene);
primaryStage.setTitle("Stage_One");
primaryStage.show();
}
private void showPopup()
{
Stage stage = new Stage();
VBox vBox = new VBox();
vBox.setAlignment(Pos.TOP_CENTER);
Label label = new Label("Stage_TWO");
Button closeStageButton = new Button("Close Stage_TWO");
closeStageButton.setOnAction(event -> stage.close());
vBox.getChildren().addAll(label, closeStageButton);
Scene scene = new Scene(vBox, 200, 200);
stage.setScene(scene);
stage.initStyle(StageStyle.UTILITY);
stage.initModality(Modality.APPLICATION_MODAL);
stage.setTitle("Stage_TWO");
stage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
对我来说,这是windows管理器的问题,而不是java/fx的问题。直到最近,在任务栏中显示窗口标题还存在问题。