有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

添加了重复子线程“JavaFX应用程序线程”中的java异常

我在使用JavaFx的应用程序中工作,我想在myStackPane中复制我的组件,但我有一个错误/异常

final Button file = new Button("fichier");
file.setGraphic(new ImageView("/images/file.png"));
final Image fichier_img = new Image("/images/file.png");
final StackPane paint = new StackPane();

 ile.setOnAction(new EventHandler<ActionEvent>() {
   public void handle(ActionEvent e) {
        File fichier = new File();
        paint.getChildren().addAll( mes_images[0]);
       //fichier.setPositionX(me.getSceneX());
    }
});
 paint.addEventHandler(MouseEvent.MOUSE_CLICKED,
    new EventHandler<MouseEvent>() {
       public void handle(MouseEvent e) {
            if (e.getButton() == MouseButton.SECONDARY)  
                menu_gauche.show(paint, e.getScreenX(), e.getScreenY());
        }
});

下面是我的错误信息:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Children: duplicate children added: parent = StackPane@658d001a at javafx.scene.Parent$2.onProposedChange(Unknown Source) at com.sun.javafx.collections.VetoableListDecorator.add(Unknown Source)


共 (1) 个答案

  1. # 1 楼答案

    似乎mes_images[0]已经添加到了StackPane中,这不应该发生。 创建一个新的Image对象(我猜它是一个图像),并将这个新实例添加到StackPane中,然后一切都会好起来

    javadoc of ^{}开始:

    A node may occur at most once anywhere in the scene graph. Specifically, a node must appear no more than once in all of the following: as the root node of a Scene, the children ObservableList of a Parent, or as the clip of a Node.