ArrayList list = new ArrayList();
CheckBox chk = new CheckBox();
list.add(chk);
取出来时要进行转换
for (int i = 0; i < list.size(); i++)
{
   CheckBox temp = (CheckBox)list.get(i);
}

解决方案 »

  1.   

    小例子
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;public class Check extends JFrame
    {
    ArrayList list = new ArrayList();
    JButton btn = new JButton("add");
    int count = 0;
    public Check()
    {
    for (int i = 0; i < 10; i++)
    {
    JCheckBox chk = new JCheckBox(String.valueOf(i));
    list.add(chk);
    }
    btn.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    if (count < list.size())
    {
    JCheckBox chk = (JCheckBox)list.get(count);
    getContentPane().add(chk);
    getContentPane().validate();
    }
    count ++;
    }
    });
    this.getContentPane().add(btn);
    this.getContentPane().setLayout(new FlowLayout());
    this.setSize(400,200);
    }
    public static void main(String[] args)
    {
    JFrame frame = new Check();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.show();
    }
    }
      

  2.   

    我想你可能是要在JList中加入JCheckBox
    这是不行的,你可以这样作:
    JScrollPane里加入JCheckBox,让这些checkbox坚直排列(在pane中使用grid layout即可)
      

  3.   

    自己写个CellRenderer, return CheckBox
    JList.setCellRenderer(myCellRenderer);
      

  4.   

    study the code:
    j2sdk \demo\jfc\swingset2\ListDemoJList with JCheckBox