2017-12-07 6 views
0

JavaFX로 작업하면서 새로운 점은 장면을 변경 한 후에 모든 구성 요소가 표시되지 않는다는 것입니다. 예를 들어, BorderPane 센터에 추가되는 GridPane가있어, Label가 BorderPane의 하단에 추가됩니다. 그러나이 레이블이 표시되지 않는 장면을 변경 한 후에는 크기 조정 후에 만 ​​작동합니다. 코드가 나를 위해 잘 작동되기 때문에,JavaFX, 윈도우의 크기를 조정 한 후에 만 ​​레이블이 표시됨

import javafx.application.Application; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.layout.GridPane; 
import javafx.stage.Stage; 
import javafx.scene.control.Label; 
import javafx.scene.control.Button; 
import javafx.scene.Scene; 

public class View extends Application implements EventHandler<ActionEvent> { 
    private Scene scene1, scene2; 
    private Button b1, b2; 
    private Stage stage; 

    public static void main(String... args) { 
     launch(args); 
    } 

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

     this.createScene1(); 
     this.stage.setScene(this.scene1); 

     this.stage.setWidth(200); 
     this.stage.setHeight(200); 
     this.stage.show(); 
    } 

    public void createScene1() { 
     BorderPane border = new BorderPane(); 
     GridPane root = new GridPane(); 

     root.add(new Label("Scene 1"), 0, 0); 
     this.b1 = new Button("Change to Scene 2"); 
     this.b1.setOnAction(this); 
     root.add(this.b1, 0, 1); 

     border.setCenter(root); 
     border.setBottom(new Label("Should be visible")); 
     this.scene1 = new Scene(border); 
    } 

    public void createScene2() { 
     BorderPane border = new BorderPane(); 
     GridPane root = new GridPane(); 

     root.add(new Label("Scene 2"), 0, 0); 
     this.b2 = new Button("Change to Scene 1"); 
     this.b2.setOnAction(this); 
     root.add(this.b2, 0, 1); 

     border.setCenter(root); 
     border.setBottom(new Label("Should be visible")); 
     this.scene2 = new Scene(border); 
    } 

    @Override 
    public void handle(ActionEvent e) { 
     if (this.b1 != null) { 
      if (this.b1 == e.getSource()) { 
       this.createScene2(); 
       this.stage.setScene(this.scene2); 
      } 
     } 
     if (this.b2 != null) { 
      if (this.b2 == e.getSource()) { 
       this.createScene1(); 
       this.stage.setScene(this.scene1); 
      } 
     } 
    } 
} 

답변

-1

나는 당신의 문제를 재현 할 수 없습니다

은 다음 간단한, 최소를 완료하고 검증 가능한 예이다. 그러나 구성 요소가 너무 많이 축소되어 렌더링되지 않을 수 있습니다. 이것을 방지하려면 접두사가 붙은 최소 너비와 높이를 사용해보십시오.

+0

Java 8에서 다시 테스트했는데 올바르게 작동합니다. Java 9에 버그가있는 것 같습니다. – Java4Life

관련 문제