8

コンストラクタの外でシーンの幅と高さを設定しようとしましたが、うまくいきませんでした。APIを調べた後Scene、高さと幅をそれぞれ取得できるメソッドを見ましたが、メソッドを設定するメソッドはありません.. :s(設計上の欠陥かもしれません)。

さらに調査したSceneBuilder結果、高さと幅を変更できるメソッドに出会い、見つけました。SceneBuilderしかし、すでに作成されているシーンオブジェクトに適用する方法や、シーンオブジェクトの代わりに使用できるオブジェクトを作成する方法がわかりません。

4

3 に答える 3

14

作成Sceneして に割り当てると、ステージとシーンの両方のサイズを同時に使用および変更Stageできます。Stage.setWidthStage.setHeight

SceneBuilder作成済みのオブジェクトには適用できません。シーンの作成にのみ使用できます。

于 2012-01-09T16:27:48.383 に答える
3

作成後にのサイズを設定することはできないようSceneです。

Stage装飾のサイズを含むウィンドウのサイズを設定する手段のサイズを設定します。したがって、が装飾されていSceneない場合を除き、サイズは小さくなります。Stage

私の解決策は、初期化中に装飾のサイズを計算し、サイズStage変更時に装飾のサイズに追加することです:

private Stage stage;
private double decorationWidth;
private double decorationHeight;

public void start(Stage stage) throws Exception {
    this.stage = stage;

    final double initialSceneWidth = 720;
    final double initialSceneHeight = 640;
    final Parent root = createRoot();
    final Scene scene = new Scene(root, initialSceneWidth, initialSceneHeight);

    this.stage.setScene(scene);
    this.stage.show();

    this.decorationWidth = initialSceneWidth - scene.getWidth();
    this.decorationHeight = initialSceneHeight - scene.getHeight();
}

public void resizeScene(double width, double height) {
    this.stage.setWidth(width + this.decorationWidth);
    this.stage.setHeight(height + this.decorationHeight);
}
于 2016-07-18T13:44:04.730 に答える
2

私と同じような問題を抱えている可能性のある人のために、別の回答を投稿したかっただけです。

http://docs.oracle.com/javase/8/javafx/api/javafx/scene/Scene.html

setWidth()またははなくsetHeight()、プロパティはReadOnlyですが、

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.

ご覧のとおり、必要に応じて高さと幅を設定できます。

私にとっては、SceneBuilderあなたが行っていたと説明したように、私は を使用しており、その幅と高さが必要でした。カスタム コントロールを作成しているので、自動的に行われないのがおかしいので、必要に応じて行う方法を次に示します。

setWidth()/ setHeight()fromも使用できたはずStageです。

于 2014-09-13T23:45:04.013 に答える