0

有没有办法将 jcheckboxes 添加到 jscrollpane 中?

我有一个复选框数组,我想将它们添加到 Jscrollpane 中,然后我将其添加到 JOptionPane 中。到目前为止,我有这个:

Object[] books = new Object[10000];
    books[0] = "Choose books to purchase: ";
    for(int l = 1;l<checkboxes.length;l++)
    {
        books[l] = checkboxes[l];
    }

    JList list = new JList(checkboxes);
    //JTextPane test = new JTextPane();
    //test.add(checkboxes[0]);

    JScrollPane myScrollPane = new JScrollPane(list);
    myScrollPane.setPreferredSize(new Dimension(250,250));




    JOptionPane.showMessageDialog(null, "Choose the books you want to purchase below.\nPlease note that each book has a $5 shipping charge.\nThe books are formatted as Title - Author - Price", "Reminder",JOptionPane.PLAIN_MESSAGE);
    JOptionPane.showMessageDialog(null,myScrollPane,"Book List",JOptionPane.OK_CANCEL_OPTION);

输出没有给我复选框,只是我认为的复选框的指针。如您所见,我尝试将复选框放入 JList 但失败了。

非常感谢你们!

4

1 回答 1

1

您可以将复选框添加到 JPanel,并且 Jpanel 可以显示在 JDialog 而不是 JOptionPane 中。要将复选框添加到 JPanel,您可以查看此链接 How to use JCheckbox array in JPanel array

于 2013-04-07T09:38:28.890 回答