init tarray 太大_模态JavaFX阶段initOwner阻止所有者调整大小,bug?

bd96500e110b49cbb3cd949968f18be7.png

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

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

here is a minimal example

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()

{

@Override

public void handle(ActionEvent event)

{

if (newStage==null)

{

Button newBtn = new Button("Close window");

newBtn.setOnAction(new EventHandler()

{

@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);

}

}

解决方案

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

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

Edit: 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值