title: Button editor for jtable button renderer
body: <p>I have a <code>Jtable</code> to which I have set a button renderer. I have successfully rendered button in one of the columns.However, I also wish to edit the buttons and for that I have used  button editor.</p>
  
  <p>Upon clicking the button,business logic is executed and button is disabled.</p>
  
  <p>The issue is if there are more than one records, then upon clicking button of one of the records, the button in that cell is disabled (as it should be).But trying to click the button of the other record,disables the button before executing the business logic and the button in previous record gets enabled.</p>
  
  <p>Now the button toggles between these two records and I am not able to click on the button of the second record.</p>
  
  <p>I am clueless as to what is leading to this issue.</p>
  
  <p>Here's an SSCCE of the problem faced by me.</p>
  
  <p>Below is code for UI Class</p>
  
  <pre><code>import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  
  
  public class TableUI  extends JFrame
  {
  JTable j = null;
  JScrollPane scp = null;
  
  public TableUI()
  {
      j = new JTable();
      j.setModel(new Tablemodel());
  
      j.setDefaultRenderer(JButton.class, new ButtonRenderer());
      j.getColumn("Column1").setCellEditor(new ButtonEditor());
  
      scp = new JScrollPane(j);
  
      add(scp);
      pack();
      setVisible(true);
  }
  
  public static void main(String[] args) 
  {
      new TableUI();
  }
  }
  </code></pre>
  
  <p>Below is the code for renderer and editor class </p>
  
  <pre><code> import java.awt.Component;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
   import java.awt.event.MouseEvent;
   import java.util.EventObject;
   import javax.swing.AbstractCellEditor;
   import javax.swing.JButton;
   import javax.swing.JTable;
   import javax.swing.table.TableCellEditor;
   import javax.swing.table.TableCellRenderer;
  
  class ButtonRenderer implements TableCellRenderer 
  {     
  JButton button;     
  boolean enabled = true; 
  
  public ButtonRenderer() 
  {     
      button = new JButton();     
  }     
  
  public Component getTableCellRendererComponent(JTable table,     
          Object value,     
          boolean isSelected,     
          boolean hasFocus,     
          int row, int column) 
  {   
  
      button.setText("Install");     
      button.setEnabled(enabled);     
      return button;     
  }     
  
  public void setEnabled(boolean enabled) 
      {     
      this.enabled = enabled;     
  }     
  }     
  
  class ButtonEditor extends AbstractCellEditor implements   
  TableCellEditor,ActionListener 
  {     
  JButton button;    
  private JTable cwwObjTblMainTable = null;
  boolean enabled = true;     
  int clickCountToStart = 1;     
  
  public ButtonEditor() 
  {     
      button = new JButton();     
      button.addActionListener(this);     
  }     
  
  public Component getTableCellEditorComponent(JTable table,     
          Object value,     
          boolean isSelected,     
          int row, int column) {     
  
      cwwObjTblMainTable=table;
      button.setText("Install");     
      button.setEnabled(enabled);     
      return button;     
  }     
  
  public void setEnabled(boolean enabled) {     
      this.enabled = enabled;     
  }     
  
  public Object getCellEditorValue() {     
      return button.getText();     
  }     
  
  public boolean isCellEditable(EventObject anEvent) {     
      if (anEvent instanceof MouseEvent) {     
          return ((MouseEvent)anEvent).getClickCount() &gt;= clickCountToStart;     
      }     
      return true;     
  }     
  
  public void actionPerformed(ActionEvent e) 
  {  
      enabled=false;
      button.setEnabled(false);
      //Business logic execution 
      System.out.println("Clicked");
  
  }     
  }
  </code></pre>
  
  <p>Below is code for Table model class </p>
  
  <pre><code> import javax.swing.JButton;
   import javax.swing.table.AbstractTableModel;
  
  
  public class Tablemodel extends AbstractTableModel
  {
  private static final Class[] columnClasses = {JButton.class,Integer.class};
  
  public int getColumnCount()
  {
      return 2;
  }
  
  public int getRowCount()
  {
      return 2;
  }
  
  @Override
  public Object getValueAt(int pRow, int pCol) 
  {
      return 1;
  }
  
  public String getColumnName(int pColumn)
  {
     String[] colheads = 
        { "Column1" , "Column2"}; 
  
     return colheads[pColumn];
  }
  
  public Class getColumnClass(int col) 
   {
          return columnClasses[col];
   }
  
  public boolean isCellEditable(int rowIndex, int columnIndex) {
      return true;
  }
  
  public void removeRow(int pRow)
  {
      fireTableRowsDeleted(pRow,pRow);
      fireTableDataChanged();
  }
  }
  </code></pre>
  
  <p>Any help on this would be appreciated.</p>