Re: JCheckBox in JTable cell




>
> is this what you're trying to do?


Yes, but I'd like the control to be a JCheckBox (to apply s listener to each).



> import java.awt.*;
> import javax.swing.*;
> import javax.swing.table.*;
>
> class Testing extends JFrame
> {
> String colNames[] = {"Col1", "Col2", "Col3", "Col4"};
> Object[][] data = null;
> DefaultTableModel dtm;
> public Testing()
> {
> setLocation(400,100);
> setDefaultCloseOperation(EXIT_ON_CLOSE);
> dtm = new DefaultTableModel(data,colNames);
> JTable table = new JTable(dtm);
> JScrollPane sp = new JScrollPane(table);
> TableColumn tc = table.getColumnModel().getColumn(0);
> tc.setCellEditor(table.getDefaultEditor(Boolean.class));
> tc.setCellRenderer(table.getDefaultRenderer(Boolean.class));
> getContentPane().add(sp);
> for(int x = 0; x < 5; x++)
> {
> dtm.addRow(new Object[]{new Boolean(false),"Row "+(x+1)+" Col 2",
> "Row "+(x+1)+" Col 3","Row "+(x+1)+" Col 4"});
> }
> pack();
> }
> public static void main (String[] args){new Testing().setVisible(true);}
> }
>


.