2

Im just changing from AWT to JavaFX. In AWT I could call pack() and the Frame sizes itself: The Frame after pack() in AWT

When im trying to programm the same window in JavaFX it looks like this, becaus i couldnt find somethin like pack():

The Frame in JavaFX without pack()

Is there an easy method like pack() in JavaFX so i can size my window fast?

Dont mark my question as duplicated, it isnt -.-. By the way, it is not the same question as this: JavaFX equivalent of Swing's pack() The reason is, that sizeToScene() does not work here. I want to resize all components in the same way as pack() has it done in AWT. that "sizeToScene()" stuff doesnt do so, it just sets the size of the stage to the size of the scene, and that is not what im looking for. As you see in my second picture, the size of the scene is already the same size of the stage, but the controls doesnt look "packed()" Thanks and regards

1 Answers1

0

The pack method has nothing to do with making a child expand to the available space of it's parent, that's just the default behavior of BorderLayout in Swing. JavaFX's BorderPane doesn't inherit this behavior. This answer has everything you need to know.

Alex
  • 642
  • 1
  • 9
  • 23
  • This doesnt work. I already tried it. The problem is not the size of my stage, i dont want to make it the same size as my Scene is. Dont you understand what i mean? On the second picture i have posted I already used the method sizeToScene() and as you see it does not "pack()" my controls the same nice way like it is in the first picture done by AWT. – ImperatorMing Aug 09 '17 at 10:54
  • Ah, you mean how each control fills all of it's available space? That doesn't have anything to do with 'pack()' afaik, it's just the default behavior of BorderLayout in swing. Unfortunately that's not the case with BorderPane. If you want to figure out how to make controls fill all the available space check this out https://stackoverflow.com/a/9833063/6948906 – Alex Aug 09 '17 at 14:10
  • 1
    Yeah nice thank you. that was exactly what im looking for. Great job thanks a lot. i added to every control the following and it works as i want it to work: button.setMaxWidth(Double.MAX_VALUE); button.setMaxHeight(Double.MAX_VALUE); – ImperatorMing Aug 09 '17 at 17:14