Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX How to set max/min window size?

Tags:

fxml

javafx-2

Does setMinSize() work on containers such as GridPane, for example? I have found that in my program 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>

and the controller class

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?

like image 746
Chechulin Avatar asked Oct 02 '12 07:10

Chechulin


People also ask

How do I create a new JavaFX window?

javafx Windows Creating a new Window // create sample content Rectangle rect = new Rectangle(100, 100, 200, 300); Pane root = new Pane(rect); root. setPrefSize(500, 500); Parent content = root; // create scene containing the content Scene scene = new Scene(content); Stage window = new Stage(); window.

What is window in JavaFX?

A top level window within which a scene is hosted, and with which the user interacts. A Window might be a Stage , PopupWindow , or other such top level. A Window is used also for browser plug-in based deployments.

What is primary stage in JavaFX?

The JavaFX Stage class is the top level JavaFX container. The primary Stage is constructed by the platform. Additional Stage objects may be constructed by the application. Stage objects must be constructed and modified on the JavaFX Application Thread.


1 Answers

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.

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

Answers to additional questions

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)

like image 95
jewelsea Avatar answered Sep 21 '22 13:09

jewelsea