javafx-2 – JavaFX如何设置最大/最小窗口大小?

栏目: Java · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/12686120/javafx-how-to-set-max-min-window-size

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

这是F XML

代码:

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

这有什么不对?是否应该有某种“窗口”最大/最小尺寸?

我假设在窗口中,你的意思是 Stage

(子类Window).

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

要设置舞台的最小或最大尺寸,请将其设置为 minHeightminWidthmaxHeightmaxWidth 属性.

其他问题的答案

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)

翻译自:https://stackoverflow.com/questions/12686120/javafx-how-to-set-max-min-window-size


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

A Byte of Python

A Byte of Python

Swaroop C H / Lulu Marketplace / 2008-10-1 / USD 27.98

'A Byte of Python' is a book on programming using the Python language. It serves as a tutorial or guide to the Python language for a beginner audience. If all you know about computers is how to save t......一起来看看 《A Byte of Python》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具