Tôi chỉ muốn đăng câu trả lời khác cho những người có thể có vấn đề tương tự như tôi.
http://docs.oracle.com/javase/8/javafx/api/javafx/scene/Scene.html
Không có setWidth()
hoặc setHeight()
, và tài sản là ReadOnly
, nhưng nếu bạn nhìn vào
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.
Như bạn có thể thấy, đây là nơi bạn có thể thiết lập chiều cao và chiều rộng nếu bạn cần phải.
Đối với tôi, tôi đang sử dụng SceneBuilder
, giống như bạn mô tả bạn đang làm và cần chiều rộng và chiều cao của điều đó. Tôi đang tạo các điều khiển tùy chỉnh, vì vậy thật lạ khi nó không tự động làm điều đó, vì vậy đây là cách thực hiện nó nếu bạn cần.
Tôi cũng có thể sử dụng setWidth()
/setHeight()
từ số Stage
.
Ok, Cảm ơn bạn. Đó là một con đường mà tôi không nghĩ đến việc sử dụng hoặc không biết tôi có thể sử dụng. Cảm ơn rất nhiều, tôi sẽ thử nó và cho bạn biết làm thế nào nó đi. – Chika
Cảm ơn rất nhiều vì điều đó. Nó hoạt động đề nghị của bạn là hoàn hảo, tuy nhiên một câu hỏi nữa. Tôi có thể xóa một cảnh hay sân khấu đúng không? Làm thế nào tôi có thể làm điều này xảy ra? – Chika
đến giai đoạn "rõ ràng" chỉ định một cảnh trống cho nó: 'stage.setScene (new Scene());'. Để xóa scene, đặt root trống: 'scene.setRoot (new Group());' hoặc xóa tất cả các con của root: 'scene.getRoot(). GetChildren(). Clear();' –