2016-04-23 5 views
0

私のコードはコンパイルされていますが、空のウィンドウがあります。 FXMLの読み込みがうまくいかないと思います。手伝ってくれてありがとう!空のウィンドウJavaFX

package application; 


import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Scene; 
import javafx.scene.layout.StackPane; 
import javafx.stage.Stage; 

public class Main extends Application { 

public static void main(String[] args) { 
     launch(args); 
    } 
@Override 
public void start(Stage primaryStage) { 

    try{ 
    StackPane stackPane = new StackPane(); 
    FXMLLoader loader = new FXMLLoader(); 
    loader.setLocation(Main.class.getResource("/StackPaneWindow.fxml")); 
    Scene scene = new Scene(stackPane); 

    primaryStage.setTitle("Hello World!"); 
    primaryStage.setScene(scene); 
    primaryStage.show(); 
} catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

}

StackPaneWindows.fxmlのみボタンを有しています。私はペーストすることができません。

答えて

1

あなたはFXMLファイルをロードする必要があります。

FXMLLoader loader = new FXMLLoader(); 
loader.setLocation(Main.class.getResource("/StackPaneWindow.fxml")); 
Parent node = loader.load() 
StackPane stackPane = new StackPane(node); 

を、あなたのFXMLファイルでルートノードとしてStackPaneを置くことができ、その後、あなたは次のようにファイルを読み込むことができます。

FXMLLoader loader = new FXMLLoader(); 
loader.setLocation(Main.class.getResource("/StackPaneWindow.fxml")); 
Scene scene = new Scene(loader.load); 
+0

ブロを!あなたは素晴らしいです! – Brade

関連する問題