我有错误的代码,但它不起作用,我不明白发生了什么?
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 中的所有节点,但它没有添加流程 Pane ,或者可能不显示它!!
最佳答案
我尝试使用您的代码,它有效:请验证图像位置,也许图像位置有问题。 试试这个:
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);
}
}
关于java - 为什么它不将图像添加到流程 Pane ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44643132/