线程中的异常" JavaFX应用程序线程"重复的孩子补充

时间:2016-04-04 15:10:37

标签: java javafx javafx-2

我在使用JavaFx的应用程序中工作,我想在我的StackPane中复制我的作曲家,并且我有错误/异常。

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());
        }
});

以下是我的错误消息:

  

线程中的异常&#34; JavaFX应用程序线程&#34;   java.lang.IllegalArgumentException:Children:重复的孩子   补充:parent = StackPane @ 658d001a at   javafx.scene.Parent $ 2.onProposedChange(未知来源)at   com.sun.javafx.collections.VetoableListDecorator.add(未知来源)

1 个答案:

答案 0 :(得分:0)

It seems that mes_images[0] is already added to the StackPane, which should not happen. Create a new Image object (I guess it is an image) and add this new instance to the StackPane then everything will be fine.

From the javadoc of Node:

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.