Use this code, I have written it myself and it works:
import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
public class Tabel extends JFrame{
int numberOfCheckBoxes=0;
JCheckBox[] checkBoxList;
String[] columns=new String[]{"Column 1","Column 2","Column 3"};
Object data[][]={
{true,new Integer(10),new String("String 1")},
{false,new Integer(20),new String("String 2")},
{true,new Integer(30),new String("String 3")}
};
JTable table;
JPanel firstPanel=new JPanel();
JPanel secondPanel=new JPanel();
@SuppressWarnings("unchecked")
public void initialize(){
table=new JTable(data,columns);
this.setTitle("Tabel");
this.setVisible(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,200);
firstPanel.setLayout(new BoxLayout(firstPanel,BoxLayout.Y_AXIS));
firstPanel.setBorder(new TitledBorder("Table"));
secondPanel.setLayout(new BoxLayout(secondPanel,BoxLayout.Y_AXIS));
secondPanel.setBorder(new TitledBorder("GUI Items"));
firstPanel.add(table.getTableHeader(),BorderLayout.PAGE_START);
firstPanel.add(table);
ArrayList<string> columnNames=new ArrayList<string>();
for(int i=0;i<table.getcolumncount();i++){
columnNames.add(table.getColumnName(i));
}
JComboBox<?> comboBox=new JComboBox(columnNames.toArray());
numberOfCheckBoxes=comboBox.getItemCount();
secondPanel.add(comboBox);
checkBoxes();
this.setLayout(new BoxLayout(this.getContentPane(),BoxLayout.Y_AXIS));
this.add(firstPanel);
this.add(secondPanel);
}
void checkBoxes(){
checkBoxList=new JCheckBox[numberOfCheckBoxes];
for(int i=0;i<checkboxlist.length;++i){>
checkBoxList[i]=new JCheckBox("CheckBox #"+i);
secondPanel.add(checkBoxList[i]);
}
}
public static void main(String[] args) {
Tabel program=new Tabel();
program.initialize();
}
}
</string></string>
Best regards.
I have used the idea that Filipe displayed.