转载

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

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

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

要设置舞台的最小或最大尺寸,请将其设置为 minHeight 和 minWidth 或 maxHeight 和 maxWidth 属性.

其他问题的答案

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

原文  https://codeday.me/bug/20190112/521833.html
正文到此结束
Loading...