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); }
这有什么不对?是否应该有某种“窗口”最大/最小尺寸?
(子类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