JCheckboxes变成了JScrollPane

时间:2013-04-06 23:57:02

标签: java swing jlist joptionpane jcheckbox

有没有办法将jcheckbox添加到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但失败了。

非常感谢你们!

1 个答案:

答案 0 :(得分:1)

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