tags:

views:

60

answers:

1

Hi

I am having a table in which i have to adda JButton.

I am doing

TableColumnModel colModel = table.getColumnModel();
    colModel.getColumn(0).setCellEditor(new MYCellEditor(new JCheckbox()));

MyCellEditor extends DefaultCellEditor{

public MyCellEditor(JCheckbox checkbox){

  super(checkbox);
 Jbutton button = new JButton("Start");
 //actionlistener for button.
 }

 }
 MyRenderer extends DefaultTablecellRenderer{

   public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
    //return a button for column ==0     
  } 

My understanding is that the Celleditor has same instance of button for all cells in a column. So if i click on one button the text changes from "Start" to "stop" but if i click on button in other row it doesnt work.. After debugging it shows that the text is alreadt Stop .

How can i have different instance of button in each row ?

+1  A: 

The article Table Button Column cited in @camickr's previous answer provides a more flexible solution, but you may find the tutorial How to Use Tables: Using Other Editors helpful, too. The ColorEditor discussed there is part of the TableDialogEditDemo, available via Java Web Start. You'll need to change the corresponding ColorRenderer accordingly.

trashgod
the example in docs really helped.
harshit