2012-01-09 5 views
5

나는 장면의 너비와 높이를 생성자 바깥에 설정하려했지만 아무 소용이 없었습니다. Scene API를 살펴본 후에 높이 및 너비를 각각 알 수있는 메서드를 보았지만 .. : s (디자인 결함 일 수 있음)를 설정하는 메서드는 아닙니다.장면 너비와 높이 설정

나는 더 이상 연구 한 후에 SceneBuilder을 발견했으며 높이와 너비를 수정할 수있는 방법을 발견했습니다. 그러나 이미 만들어진 장면 개체에 적용하는 방법이나 장면 개체 대신 사용할 수있는 SceneBuilder 개체를 만드는 방법을 모르겠습니다.

답변

8

Scene을 만들고 Stage에 할당하면 Stage.setWidthStage.setHeight을 사용하여 스테이지와 장면 크기를 동시에 변경할 수 있습니다.

SceneBuilder은 이미 생성 된 개체에 적용 할 수 없으며 장면 생성에만 사용할 수 있습니다.

+0

좋아, 감사합니다 :

내 솔루션 크기 조절시 초기화 동안 장식의 크기를 계산하고 Stage의 크기에 추가하는 것입니다. 그것은 내가 사용하는 것을 생각하거나 사용하지 못하려는 생각이 들지 않는 길입니다. 고마워, 내가 그것을 밖으로 시도하고 어떻게 갔는지 알려주. – Chika

+0

고맙습니다. 그러나 제안은 완벽했지만 한 번 더 질문합니다. 나는 장면이나 무대를 깨끗하게 할 수 있어야합니까? 어떻게해야합니까? – Chika

+1

"지우기"단계는 빈 장면을 지정합니다 :'stage.setScene (new Scene());'. 장면을 지우려면, 빈 root :'scene.setRoot (new Group());'을 설정하거나 root의 모든 자식을 제거하십시오 :'scene.getRoot() .getChildren(). clear();' –

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을 사용하고 있으며 그 너비와 높이가 필요했습니다. 나는 사용자 정의 컨트롤을 작성하므로 자동으로 수행하지 않는 것이 이상한 일 이었으므로 필요한 경우이 작업을 수행하는 방법입니다.

Stage에서 setWidth()/setHeight()을 사용할 수있었습니다.

0

Scene을 만든 후에는 크기를 설정할 수없는 것 같습니다.

Stage의 크기 설정은 장식의 크기를 포함하여 창의 크기를 설정하는 것을 의미합니다. 따라서 SceneStage이 장식되지 않은 경우 크기가 작습니다.

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); 
}