1

My problem is that my JavaFX window expands further than it should at the bottom, thus showing a weird blank background...

I set stage.setResizable(false) but it doesn't seem to work. I also set

stage.setMinWidth(1280);
stage.setMaxWidth(1280);
stage.setMinHeight(800);
stage.setMaxHeight(800);

I think it's due to some ImageView bigger than the window, but I really would like my window to stick to the max I set and be absolutely not resizable ever.

Here's what it looks like : click here

I also noticed it happens only when I set stage.initStyle(StageStyle.TRANSPARENT). But I don't want my window to be decorated with stage.initStyle(StageStyle.DECORATED)... :(

Thank you in advance for your help. :)

Torayl
  • 57
  • 6
  • What makes you sure the height it is is not 800? – nhouser9 Feb 12 '17 at 02:18
  • Because when I don't put this node which overflow the window, it works well. And because I know what 1280*800 looks like. – Torayl Feb 12 '17 at 02:38
  • Fair enough. I upvoted, hopefully this gets some more attention. Check this out and see if it helps: http://stackoverflow.com/questions/20732100/javafx-why-does-stage-setresizablefalse-cause-additional-margins – nhouser9 Feb 12 '17 at 02:43
  • I tried it out, and it didn't work :( – Torayl Feb 12 '17 at 03:02

1 Answers1

1

Have you tried directly using setWidth and setHeight:

stage.setWidth(1280);
stage.setHeight(800);

I think the setMaxWidth, setMinHeight... etc. only works on a decorated screen because its main purpose is to limit the sizes the user can set the window. Here's my example:

public class FixedWindowSize extends Application
{

    public static void main(String[] args)
    {
        Application.launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        Pane p = new Pane();
        p.setBackground(new Background(new BackgroundFill(Color.RED, null, null)));
        p.setMinSize(6000, 6000); //Make this go out beyond window bounds.
        Scene s = new Scene(p);

        primaryStage.setScene(s);
        primaryStage.initStyle(StageStyle.TRANSPARENT);

        //This doesn't work
        //primaryStage.setMinWidth(1280);
        //primaryStage.setMaxWidth(1280);
        //primaryStage.setMinHeight(800);
        //primaryStage.setMaxHeight(800);

        //This should work.
        primaryStage.setWidth(1280);
        primaryStage.setHeight(800);

        primaryStage.show();
    }

}
theKidOfArcrania
  • 488
  • 4
  • 13
  • I feel stupid I didn't think of that... It really makes sense now. Thank you very much for your answer! :) – Torayl Feb 12 '17 at 03:33