Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

scene window resize problem

3da11222-766b-4d2b-9895-ca69698a8b30Apr 17 2017 — edited Apr 19 2017

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?

Comments

omers

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

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

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

omers

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

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

1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 17 2017
Added on Apr 17 2017
5 comments
486 views