title: actionPerformed on JButton as TableCellEditor incorrectly invoked on MouseDown
body: <p>I'm trying to use a <code>JButton</code> as <code>TableCellRenderer</code> and <code>TableCellEditor</code> for my <code>JTable</code>. In my test scenario I have 5 rows which each shows a <code>JButton</code> as Renderer and Editor (different button instances for editor and renderer). When I click on one button for the first time <code>actionPerformed</code> of the editor-button is invoked, when I RELEASE the mouse button. When I click on another button in another row then, the <code>actionPerformed</code>-Event of the editor-button is already invoked, when I put the mouse button down (<code>MOUSE_PRESSED</code>). This behaviour doesn't seem right. Usually the <code>actionPerformed</code>-event is invoked when releasing the mouse button, not when pressing it. When pressing another button in another row afterwards, <code>actionPerformed</code> is again invoked correctly when releasing the mouse button, on the next button click in another row <code>actionPerformed</code> is again (incorrectly) invoked on <code>MOUSE_DOWN</code> and so forth.</p>
  
  <p>When moving the focus out of the table and then clicking on a button, <code>actionPerformed</code> is invoked correctly when releasing the mouse button. Also when the table row editor in the row the button to be clicked is in is first focused (activated) and then the button is clicked, the behaviour also is correct. Then only situation when it doesn't work is when a table cell editor is active and then the button in another table row is clicked.</p>
  
  <p>Comparing the stacktraces when <code>actionPerformed</code> is invoked in both cases I found out that in the incorrect case <code>DefaultKeyboardFocusManager(KeyboardFocusManager).redispatchEvent</code> and <code>BasicButtonListener.focusLost(FocusEvent)</code> are invoked, which both look suspicious to me.</p>
  
  <p>Here is a little demonstration code for my problem:</p>
  
  <pre><code>import java.awt.Component;
  import java.awt.Dimension;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.AbstractCellEditor;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JTable;
  import javax.swing.table.AbstractTableModel;
  import javax.swing.table.TableCellEditor;
  import javax.swing.table.TableCellRenderer;
  
  public class TableButtonTest extends JFrame
  {
  
      private JTable  table;
  
      public TableButtonTest()
      {
          super("TableButtonTest");
  
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          JPanel contentPane = new JPanel(new GridLayout(1, 0));
          contentPane.setOpaque(true);
          setContentPane(contentPane);
  
          table = new JTable(new MyTableModel());
          table.setPreferredScrollableViewportSize(new Dimension(500, 70));
          add(table);
  
          setPreferredSize(new Dimension(600, 200));
  
          TableCellRenderer defaultBtnRenderer = new TableCellRenderer()
          {
              private JButton btn = new JButton("aa");
  
              public Component getTableCellRendererComponent(JTable _table, Object value,
                  boolean isSelected, boolean hasFocus, int row, int column)
              {
                  return btn;
              }
          };
  
          table.getColumnModel().getColumn(0).setCellRenderer(defaultBtnRenderer);
          table.getColumnModel().getColumn(0).setCellEditor(new ButtonEditor());
  
          pack();
          setVisible(true);
  
      }
  
      public class ButtonEditor extends AbstractCellEditor implements TableCellEditor
      {
          private JButton btn = new JButton("bb");
          {
              btn.addActionListener(new ActionListener()
              {
  
                  public void actionPerformed(ActionEvent e)
                  {
                      System.out.println("BUTTON EVENT");
                  }
              });
          }
  
          public Component getTableCellEditorComponent(JTable _table, Object value, boolean isSelected,
              int row, int column)
          {
              return btn;
          }
  
          public Object getCellEditorValue()
          {
              return null;
          }
      }
  
      class MyTableModel extends AbstractTableModel
      {
          public int getColumnCount()
          {
              return 1;
          }
  
          public int getRowCount()
          {
              return 5;
          }
  
          public Object getValueAt(int row, int col)
          {
              return null;
          }
  
          @Override
          public boolean isCellEditable(int row, int col)
          {
              return true;
          }
      }
  
      public static void main(String[] args)
      {
          new TableButtonTest();
      }
  }
  </code></pre>
  
  <p>When you start the program and hit any of the "aa" buttons, it turns to "bb" (indicating that the editor is shown instead of the renderer) and when you release the mouse button "BUTTON EVENT" is printed on STDOUT. If you click on another button in another row then, it also turns to "bb" but "BUTTON EVENT" is already printed to STDOUT before you release the mouse button. And also the focus rectangle around the button text isn't shown.</p>
  
  <p>I tested this behaviour with Java 1.6.0_26 and 1.6.0_27. When I used 1.5.0_17 it got event worse: When clicking on the second button NO actionPerformed was invoked, only the "bb"-button was shown. The third click then again worked correctly, the fourth didn't and so forth. So the difference to Java 1.6 is, that on 1.6 on the second (and fourth, ...) click actionPerformed is invoked when releasing the mouse button, on 1.5 is isn't invoked at all.</p>
  
  <p>But I dont care about 1.5, I just want it to work with 1.6.</p>
  
  <p>What can I do to make this work?</p>
  
  <p>Thanks.</p>