0

Let us have a JavaFX program with the scene graph Group -> Canvas. The root (Group) is put inside a Scene, and the Scene is attached to a Window, specifically a Stage.

Once the Window is displayed on screen, the user may resize the Window. The height and the width may be changed. However, there are usually some restrictions to how small the Window can be made. Notably the Window has a titlebar, and it has an associated minimum width. See also the picture below.

I suspect that the minimum width of the titlebar is platform-dependent and further depends on user settings of the platform. So a more-less general way of accessing the parameter is desirable.

  • Is it possible to generally access the minimum (stable) width of the titlebar of a Window? If so, how?

A picture to explain concisely which length I am looking for:

Example

(In the picture, the Window could not be made any smaller in the horisontal dimension).


Here is a MWE for testing (please try to decrease the horisontal width as far as possible):

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.stage.Stage;


public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) {
        Group group = new Group();
        Canvas canvas = new Canvas(200, 200);
        group.getChildren().add(canvas);
        
        Scene scene = new Scene(group);
        stage.setTitle("Title");
        stage.setScene(scene);
        stage.show();

        //System.out.println(stage.getMinWidth()); // default is also 0.0
        //stage.setMinWidth(0); // we can see that a lower value than the sought-for minimum value will not have an effect


    }

    public static void main(String[] args) {
        launch();
    }
}
  • Are you looking for [this](https://stackoverflow.com/questions/12686120/javafx-how-to-set-max-min-window-size)? – SedJ601 Apr 25 '22 at 19:09
  • @Sedrick **No**, afaict. Unfortunately, the ``stage.getMinWidth()`` is something different. One can do ``stage.setMinWidth(0)`` if one so desires. But the minimum width I am looking for will happily ignore this and remain some (platform, setting-dependent) positive constant as shown in the picture. – Linear Christmas Apr 25 '22 at 19:19
  • 1
    Set the stage width to 0, show the stage, [get the width](https://openjfx.io/javadoc/17/javafx.graphics/javafx/stage/Window.html#getWidth()) of the stage. – jewelsea Apr 25 '22 at 20:18
  • 3
    I just wonder why you need to know that? Typically (though windows are rendered natively, so behave a bit differently), JavaFX uses a top-down layout strategy, so minimum sizes of containers are determined by the minimum sizes of their content nodes (and how they’re laid out). So normally you wouldn’t really care about the minimum size of the window. It sounds a little like you are trying to find the wrong solution to some other unstated problem. – James_D Apr 25 '22 at 20:24
  • @jewelsea That does**n't** work, afaict. The canvas attached to the stage has already has dimensions. So if the stage width is set to 0, it will be ignored: the size of the stage will be the size of the scene + left edge and + right edge. These parameters may be found, of course, but they are not related to the minimum width of the titlebar as in OP. There are other options to finding out what the minimum width of the titlebar is, which do work, but are **local**, *not* global in nature. These include adding a listener to the width property and printing out the width after resizing to minimum. – Linear Christmas Apr 27 '22 at 09:00
  • @jewelsea The hope in the OP was to find out the parameter after showing the stage but the code/program would be final by this time, with no additional tinkering or action from the user to find out the minimum width. – Linear Christmas Apr 27 '22 at 09:03
  • @James_D You are correct in that the OP was partly inspired by another problem. I decided to omit it because 1) I can more or less solve that problem in another way; 2) the OP still interests me regardless of the particular original inspiration. So, for instance, can one set the **initial** showing size of the stage to be exactly twice the minimum possible size? There are also other questions of analogous nature I might ask in the future: is it possible to find the cursor parameters (height, length) in a "global" sense etc. Hopefully this adds some background to the question. Thank you! – Linear Christmas Apr 27 '22 at 09:08
  • With the extra info, I guess I don't really understand the question and can't offer any advice on a solution. – jewelsea Apr 27 '22 at 19:23

0 Answers0