Forum Stats

  • 3,838,708 Users
  • 2,262,394 Discussions
  • 7,900,739 Comments

Discussions

scene window resize problem

3da11222-766b-4d2b-9895-ca69698a8b30
edited Apr 19, 2017 8:14PM in JavaFX 2.0 and Later

i am a beginner and my first javafx program from the already given code.   i want to resize the scene window with following command

Scene scene = new Scene(root, 300, 100);

no matter what numbers i enter i always get full screen.   i am using netbeans.  please tell me how can i resize the start scene window?

Answers

  • omers
    omers Member Posts: 13
    edited Apr 17, 2017 6:41AM

    If you are at the beginning level in JavaFX, you can use Scene Builder(JavaFX Scene Builder 1.x Archive ).

    Set size of root component, under the layout tab, in the size section, PREF_WIDTH and PREF_HEIGHT fields.

    screenshot.png

    And your code can be like this.

    Scene scene = new Scene(root);
  • bouye-JavaNet
    bouye-JavaNet Member Posts: 394 Silver Badge
    edited Apr 18, 2017 8:48PM

    Also setting the size of the scene does not equals setting the size of the window. Window (stage) may have additional decorations and border width/insets. The size of the window can be directly set on the stage itself.

    So you have 3 "layers" of dimensions:

    • The min, pref, max size of the content (when the content is resizable) AS WELL AS the actual size of the content (those may be different). You have properties for all 4. Depending how you define your content some may not be realized before the content is displayed at least once.
    • The initial size of the scene upon creation which may not be respected when the content is layed into it.
    • The size of the stage itself. If not set, it may or may not attempt to adapt itself to the size of the scene OR its content.
  • omers
    omers Member Posts: 13
    edited Apr 19, 2017 1:40AM

    What happens if you leave the scene size blank and root layout takes width and height ?

  • omers
    omers Member Posts: 13
    edited Apr 19, 2017 1:59AM

    Use the right way for dynamic window size : https://gist.github.com/omernaci/94c767e519139464edc7a8092cabd415

    Be very happy if you share your thoughts, thanks for relating.

  • bouye-JavaNet
    bouye-JavaNet Member Posts: 394 Silver Badge
    edited Apr 19, 2017 8:14PM

    You can replace all your calls to AWT classes with the JavaFX javafx.stage.Screen class instead. Except for that I do not see what would be the issue here? What are you trying to achieve with this simple test?

    As for your question, usually it takes the preferred / computed dimensions. Now again it depends of what's your content. Groups and basic nodes are not resizable for example, whereas most layouts and controls (anything that inherit from Region) are.

    Also ScrollPane allows for things to go out of display

This discussion has been closed.