I know that with JavaFX you can set the Stage min size using stage.setMinWidth()
and stage.setMinHeight()
, however, this will include the window bo
You can show the Stage
undecorated, which will remove all the borders:
primaryStage.initStyle(StageStyle.UNDECORATED);
If you want to have it decorated
If you want to have it decorated you can set the size of the Scene
to the preferred minimum size, then show the window (the Stage
will have the size to be able to display the Scene
with that size which one actually is your needed minimum size), then set the minimal size to the current size.
Example:
public class Main extends Application {
private final int PREF_MIN_WIDTH = 500;
private final int PREF_MIN_HEIGHT = 500;
@Override
public void start(Stage primaryStage) {
try {
Scene scene = new Scene(new HBox(), PREF_MIN_WIDTH, PREF_MIN_HEIGHT);
primaryStage.setScene(scene);
primaryStage.showingProperty().addListener((observable, oldValue, showing) -> {
if(showing) {
primaryStage.setMinHeight(primaryStage.getHeight());
primaryStage.setMinWidth(primaryStage.getWidth());
primaryStage.setTitle("My mininal size is: W"+ primaryStage.getMinWidth()+" H"+primaryStage.getMinHeight());
}
});
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
This will produce a window like this:
Inside void start(Stage primaryStage)
, put the following:
primaryStage.initStyle(StageStyle.UNDECORATED);