将数据传递给其他表单并更新表单

Pass Data to other Forms and update Form

在我的应用程序中,我希望用户能够不断地将歌曲添加到 FormA 中的列表中。然后 FormB 会将添加的歌曲显示为标签。

我知道如何创建标签列表,但不幸的是,添加的歌曲不会出现在 FormB 中。我需要一种方法来在每次添加歌曲时更新 FormB,因此 FormB 始终是最新的。

这是我试过的:

public void createPlaylist() {
    for (int i = 0; i < songList.getSongList().size(); i++) {
        Button temp = new Button(songList.getSongList().get(i).toString());
        listCont.add(temp); //add Buttons to the List-Container for every Song in the List
    }
    centerCont.removeComponent(listCont); 
    centerCont.removeComponent(bottomCont); //remove Containers to add the updated ones (?)
    centerCont.add(listCont).add(bottomCont); //add updated Containers
}

这不起作用,因为应该显示新添加的按钮的 FormB 没有这样做。

如何实现?

感谢 Diamond Mubaarak,我设法解决了这个问题。我只是将表单传递给彼此,所以我在 FormB 方法中调用 FormA.revalidate();