public void handle(ActionEvent event) {
ScrollPane sPane=paneItem();
scene = new Scene(sPane, 400, 600);
System.out.println(scene.getWidth()+","+scene.getHeight());
stage.setScene(scene);
System.out.println(scene.getWidth()+","+scene.getHeight());
stage.show();
System.out.println(scene.getWidth()+","+scene.getHeight()+","+stage.getWidth()+","+stage.getHeight());
}
运行这些代码后,结果是:
400.0,600.0
400.0,600.0
410.0,610.0,416.0,639.0
窗口大小现在为416 * 639。
为什么在调用stage.show()
之后场景的宽度突然增加了10?
,然后再用另一种方法:
private void mnt() {
...
mntButton.setOnAction(t -> {
System.out.println(completeMnt());
mntButton.setText("complete");
stage.setScene(new Scene(paneItem(),400,600));
System.out.println(scene.getWidth()+","+scene.getHeight()+","+stage.getWidth()+","+stage.getHeight());
});
}
结果是:
410.0,610.0,406.0,629.0
在这里,我尝试更改场景的内容并保持大小不变, 但是窗口的大小缩小到406 * 629
scene
和stage
都是类变量。