Po prostu chciałem zamieścić inną odpowiedź dla tych, którzy mogli mieć podobny problem jak mój.
http://docs.oracle.com/javase/8/javafx/api/javafx/scene/Scene.html
Nie ma setWidth()
lub setHeight()
, a nieruchomość jest ReadOnly
, ale jeśli spojrzeć na
Constructors
Scene(Parent root)
Creates a Scene for a specific root Node.
Scene(Parent root, double width, double height)
Creates a Scene for a specific root Node with a specific size.
Scene(Parent root, double width, double height, boolean depthBuffer)
Constructs a scene consisting of a root, with a dimension of width and height, and specifies whether a depth buffer is created for this scene.
Scene(Parent root, double width, double height, boolean depthBuffer, SceneAntialiasing antiAliasing)
Constructs a scene consisting of a root, with a dimension of width and height, specifies whether a depth buffer is created for this scene and specifies whether scene anti-aliasing is requested.
Scene(Parent root, double width, double height, Paint fill)
Creates a Scene for a specific root Node with a specific size and fill.
Scene(Parent root, Paint fill)
Creates a Scene for a specific root Node with a fill.
Jak widać, jest to, w którym można ustawić wysokość i jeśli szerokość musisz.
Dla mnie używam SceneBuilder
, tak jak to opisywałeś i potrzebowałeś szerokości i wysokości tego. Tworzę niestandardowe formanty, więc dziwne było, że nie zrobiły tego automatycznie, więc tak to zrobić, jeśli trzeba.
Mogłem też użyć setWidth()
/setHeight()
z Stage
.
Ok, dzięki. To jest droga, którą nie myślałem o użyciu lub nie wiedziałem, że mógłbym użyć. Wielkie dzięki, wypróbuję to i dam ci znać, jak poszło. – Chika
Wielkie dzięki za to. To działa, twoja sugestia była doskonała, jednak jeszcze jedno pytanie. Powinienem być w stanie usunąć scenę lub etap, prawda? Jak mogę to zrobić? – Chika
do etapu "wyczyszczenia" przypisać do niego pustą scenę: 'stage.setScene (new Scene());'. Aby wyczyścić scenę, ustaw pusty root: 'scene.setRoot (new Group());' lub usuń wszystkie elementy potomne root'a: 'scene.getRoot(). GetChildren(). Clear();' –