This discussion is archived
4 Replies Latest reply: Jan 14, 2013 6:12 AM by colin-java RSS

Struggling with resizing

colin-java Newbie
Currently Being Moderated
Hi, I have a javafx application, its basically that game with tiles that makes a picture (But I'm doing it with movies).

So basically, in the
public void start(Stage primaryStage) method:
////////////////////////////////////////////////////////////////////////////////////////////
Board board = new Board(); [ THIS EXTENDS GROUP, AND HAS LOTS OF MEDIAVIEWS ADDED TO ITS CHILDREN]

Group root = new Group();
root.setDepthTest(DepthTest.DISABLE);
root.getChildren().addAll(board);

Scene scene = new Scene(root)

primaryStage.setScene(scene);
primaryStage.show();
////////////////////////////////////////////////////////////////////////////////////////////

So basically, I want the scene to fit perfectly around the board, I think I have to use binding somehow,
but I'm being overwhelmed with code when I try to read the javafx api, and I'm not getting anywhere by just playing around with it.
Also, if the boards children get bigger or smaller, I'd like the scene to adjust its size, so it still fits nicely.

Can anyone help?
Thanks
  • 1. Re: Struggling with resizing
    svanimpe Newbie
    Currently Being Moderated
    You can find out the Window (Stage) a node is in with node.getScene().getWindow().
    You can resize a Window to fit the preferred size of its scene with window.sizeToScene().

    Maybe that can help with your problem.
  • 2. Re: Struggling with resizing
    984080 Explorer
    Currently Being Moderated
    Hi,

    I'm not experienced with the Group element, but from the API I see:
    -->A Group will take on the collective bounds of its children and is not directly resizable.

    Why not making use of a StackPane as parent element, and instead of extending from Group, extend from a Tile Pane or a Flow Pane?
    Those containers resizes easelly. Don't forget to set the Max Width and Max Height to MAX_VALUE!

    Hope this helps..
  • 3. Re: Struggling with resizing
    colin-java Newbie
    Currently Being Moderated
    Marvellous, I put the sizeToScene() method in the board class, just after the Tiles are added, and it works.
    Thanks for that, it was critical part of my program.

    I just need to get my MenuBar to stretch across the size of the window, there's currently a big gap to the right of the FileMenu,
    I'm not too sure how to do it.

    Any thought(s)?
  • 4. Re: Struggling with resizing
    colin-java Newbie
    Currently Being Moderated
    Thanks for help, didn't see your message till just, I will have a play around with it soon. Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points