Volevo solo pubblicare un'altra risposta per coloro che potrebbero avere avuto un problema simile al mio.
http://docs.oracle.com/javase/8/javafx/api/javafx/scene/Scene.html
Non c'è setWidth()
o setHeight()
, e la proprietà è ReadOnly
, ma se si guarda al
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.
Come potete vedere, questo è dove è possibile impostare l'altezza e la larghezza, se devi.
Per me, sto usando SceneBuilder
, proprio come hai descritto che stavi facendo, e avevo bisogno della larghezza e dell'altezza di quello. Sto creando controlli personalizzati, quindi era strano che non lo facesse automaticamente, quindi questo è come farlo se necessario.
Avrei potuto usare setWidth()
/setHeight()
dal Stage
pure.
Ok, Grazie. Questa è una strada che non ho pensato di usare o non sapevo di poter usare. Grazie mille, lo proverò e ti farò sapere come è andata. – Chika
Grazie mille per quello. Funziona il tuo suggerimento era perfetto, tuttavia una domanda in più. Dovrei essere in grado di cancellare una scena o una scena, giusto? Come posso farlo accadere? – Chika
allo stage "clear" assegna ad esso una scena vuota: 'stage.setScene (new Scene());'. Per cancellare la scena, imposta una radice vuota: 'scene.setRoot (new Group());' oppure rimuovi tutti i figli di root: 'scene.getRoot(). GetChildren(). Clear();' –