2017-06-20 24 views
1

私はそれが動作しませんブローコードを持っている私は何が問題なのか理解できませんか?なぜフローウィンドウにイメージが追加されないのですか?

FlowPane flowPane = new FlowPane(); 
System.out.println("log:brows song"); 
for (int i = 0; i < 10; i++) { 
    Image image = new Image(new File("sample/image/2.jpg").toURI().toString()); 
    ImageView imageView = new ImageView(image); 
    flowPane.getChildren().add(imageView); 
} 
mainAnchorePaneArtist.getChildren().clear(); 

mainAnchorePaneArtist.getChildren().add(flowPane); 

それをすべてクリアmainAnchorePaneArtist内のノードが、それはフローペインを追加していないか、それを示さないかもしれ!!

+0

例外はありますか? – c0der

+0

'ファイルファイル=新しいファイル(" sample/image/2.jpg "); \t System.out.println(file.exists()); 'おそらくfalseを出力します。 – c0der

答えて

2

私はあなたのコードで試してみました:それは動作します:画像の場所を確認してください、おそらく画像の場所に問題があります。 試用:

public class MainClass extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     try { 
       AnchorPane group = new AnchorPane(); 
       Scene scene = new Scene(group ,600, 300); 
       primaryStage.setTitle("Sample Application"); 
       primaryStage.setScene(scene); 
       FlowPane flowPane = new FlowPane(); 
       System.out.println("log:brows song"); 
       for (int i = 0; i < 10; i++) { 
        Image image = new Image(new File("2.jpg").toURI().toString()); 
        ImageView imageView = new ImageView(image); 
        flowPane.getChildren().add(imageView); 
       } 
       group.getChildren().clear(); 

       group.getChildren().add(flowPane); 
       primaryStage.show(); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 
    public static void main(String[] args) { 
     launch(args); 
    } 

} 
関連する問題