JavaFX如何设置最大/最小窗口大小? [英] JavaFX How to set max/min window size?

查看:564
本文介绍了JavaFX如何设置最大/最小窗口大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

setMinSize()是否可用于容器,例如GridPane?我发现在我的程序中GridPane忽略min.手动调整大小时调整大小属性. 这是FXML代码:

Does setMinSize() work on containers, GridPane for example? I have found that in my programm GridPane ignores min. size properties while resized manually. Here is the FXML code:

<GridPane fx:id="gp" prefHeight="134.0" prefWidth="238.0" xmlns:fx="http://javafx.com/fxml" fx:controller="javafxapplication12.SampleController">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>
</GridPane>

和控制器类

public class SampleController implements Initializable {

    @FXML
    private GridPane gp;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
    gp.setMaxWidth(700);
    gp.setMinSize(200, 200);
    }   

这是怎么了?应该有某种窗口"最大/最小尺寸吗?

What's wrong here? Should there be some sort of a 'window' max/min size?

推荐答案

我要假设按窗口表示,您的意思是

I am going to assume that by window, you mean a Stage (which subclasses Window).

窗口大小可以不同于场景的根容器大小.您可以将窗口或舞台视为场景中的独立视口,其大小可以大于或小于场景根的最小和最大规格.

The window size can vary from the root container size for the scene. You can think of a window or stage as an independent viewport into the scene which can be sized larger or smaller than the min and max specifications of the scene root.

要设置舞台的最小或最大大小,请设置为 minWidth maxHeight

To set the minimum or maximum size of the Stage, set it's minHeight and minWidth or maxHeight and maxWidth properties.

其他问题的答案

可以将舞台设置为适合整个显示器"的尺寸吗?

Can the Stage be set to "fit whole display" size?

stage.setFullScreen(true)

但是如何通过单击标题栏使尺寸与我们使尺寸相同?

But how to make the size as same as we make size by clicking on the title bar?

stage.setMaximized(true)

这篇关于JavaFX如何设置最大/最小窗口大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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