模态JavaFX阶段initOwner阻止所有者调整大小,bug? [英] modal JavaFX stage initOwner prevents owner from resizing, bug?

查看:702
本文介绍了模态JavaFX阶段initOwner阻止所有者调整大小,bug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我打开另一个JavaFX(模态) Stage ,并将其所有者设置为原始 Stage ,那么原始 Stage 无法调整大小,使用窗口右下角的Windows拖动小部件

If I open another JavaFX (modal) Stage, and set its owner as the original Stage, then the original Stage can't be resized, using the windows drag widget on the bottom right hand corner of the window

我在Linux中看到这个,但没有自己的Windows或MacOS,所以不能在别处测试...

I see this in Linux but don't own windows or MacOS so can't test it elsewhere...

这里是一个最小的例子

import javafx.stage.*;
import javafx.scene.*;
import javafx.event.*;
import javafx.application.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;

public class HelloWorld extends Application
{
    static Stage newStage;

    @Override
    public void start(Stage primaryStage)
    {
        Button btn = new Button();
        btn.setText("open window");
        btn.setOnAction(new EventHandler<ActionEvent>()
        {
            @Override
            public void handle(ActionEvent event)
            {
                if (newStage==null)
                {
                    Button newBtn = new Button("Close window");
                    newBtn.setOnAction(new EventHandler<ActionEvent>()
                    {
                        @Override
                        public void handle(ActionEvent event)
                        {
                            //newStage.hide(); // either or
                            newStage.close();
                        }

                    });
                    newStage = new Stage();
                    newStage.initModality(Modality.WINDOW_MODAL); 
                    newStage.initOwner(primaryStage);    // BUG doing this, makes main window fixed size
                    newStage.initStyle(StageStyle.DECORATED);
                    StackPane newRoot = new StackPane();
                    newRoot.getChildren().add(newBtn);
                    Scene newScene = new Scene(newRoot,200,160);
                    newStage.setScene(newScene);

                }
                newStage.show();
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args)
    {
        launch(args);
    }
}


推荐答案

这是一个确认的Java错误。看起来它有时会在Java 10中修复。

This is a confirmed Java bug. Looks like it's targeted for fixing in Java 10 sometime.

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8140491

那说,我如果有人有一个解决方法,我会喜欢。

That said, I'd love a workaround if someone has one.

编辑:我找到的一个解决方法,实际上是丑陋的,你可以隐藏并显示所有者阶段隐藏模态子阶段。这样可以重新调整大小。你看到舞台消失并再次出现,这很麻烦。

one workaround I've found, ugly as it is, is that you can hide and show the owner stage after hiding the modal child stage. That re-enables resizing. You see the stage disappear and reappear, though, which is messy.

这篇关于模态JavaFX阶段initOwner阻止所有者调整大小,bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆