2016-10-07 1 views
1

기본 JavaFx 프로그램을 만들고 있습니다. 프로그램은 첫 번째 장면에 텍스트와 버튼을 표시하고 버튼을 클릭하면 프로그램이 다른 장면으로 이동합니다. 코드는 제대로 실행되지만 창에 버튼이나 텍스트가 표시되지 않습니다. 아무도 이것이 왜 일어나고 있는지 제안 할 수 있습니까? 모든 입력을 많이 주시면 감사하겠습니다. 아래의 전체 프로그램 : 여기JavaFX UI 요소가 스테이지에 표시되지 않습니다.

import javafx.application.*; 
import javafx.application.*; 
import javafx.event.*; 
import javafx.scene.*; 
import javafx.scene.control.Button; 
import javafx.scene.control.Label; 
import javafx.scene.layout.StackPane; 
import javafx.scene.layout.VBox; 
import javafx.stage.*; 

public class Main extends Application{ 

Stage window; 
Scene scene1, scene2; 

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

@Override 
public void start(Stage primaryStage) throws Exception { 
    window = primaryStage; 

    //Create Elements for scene1 
    Label label = new Label("Welcome to scene 1 click button to go to scene 2"); 
    Button button = new Button("Go to scene 2"); 
    button.setOnAction(e -> window.setScene(scene2)); 

    //Add Elements and set layout for scene1 
    StackPane layout1 = new StackPane(); 
    layout1.getChildren().addAll(button, label); 
    scene1 = new Scene(layout1, 400, 400); 

    //Create Elements for scene2 
    Label label2 = new Label("This is scene 2 click button to go back to scene 1"); 
    Button no2button = new Button("Go back to scene 1"); 
    no2button.setOnAction(e -> window.setScene(scene1)); 

    //Add Elements and set layout for scene2 
    StackPane layout2 = new StackPane(); 
    layout1.getChildren().addAll(no2button, label2); 
    scene1 = new Scene(layout2, 400, 400); 

    window.setScene(scene1); 
    window.setTitle("CSS Alarm"); 
    window.show(); 
} 
} 

답변

1

:

StackPane layout2 = new StackPane(); 
     layout1.getChildren().addAll(no2button, label2); 
     scene1 = new Scene(layout2, 400, 400); 

당신은 실제로 있지만, 바로이 장면으로 레이아웃이 설정되어이 아래 배치 2에 아무것도 추가하지 않는

scene1 = new Scene(layout2, 400, 400); 


     window.setScene(scene1); 
     window.setTitle("CSS Alarm"); 
     window.show(); 
+0

하하 사과 내가 그걸 어떻게 놓쳤는 지 모르겠다. 고마워요. –

관련 문제