开发者

Adding button to a jtable

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 Celledito开发者_运维技巧r 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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜