1

这是我的代码。为什么这些值没有进入第二个 JList?此外,第二个 Jlist 不可见。所有导入都已到位,并且在以下代码中不可见:

public class Gui extends JFrame {

    private JList l;
    private JList l2;
    private JButton b1;
    public String [] cd = {"Album a", "Album b", "Album c", "Album d","Album e", "Album f", "Album g", "Album h"}; 

    public Gui(){

    super("Mover");
    l = new JList (cd);
    l.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    b1 = new JButton("Move");

    b1.addActionListener(
            new ActionListener(){
                public void actionPerformed(ActionEvent event){
                    l2.setListData(l.getSelectedValuesList());
                }
            }
);


    setLayout(new FlowLayout());
    add(new JScrollPane(l));
    add(b1);
    add(new JScrollPane(l2));

}
}
4

1 回答 1

1

JList l2是空的,你需要先初始化它才能像你一样使用它l

添加

l2 = new JList (/*your list2 or empty*/);

就在你初始化之后JList l

编辑正如我现在看到的,评论中提到了

于 2013-06-28T09:19:40.350 回答