Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6669521

Disabling a JTable does not cancel ongoing edits

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_03"
      Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
      Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      In a JTable where a cell is being edited, the cell edit remains active and sensitive to user input after calling setEnabled(false) on the JTable.

      A JTextField behaves as expected and cancels ongoing edits.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile & run included code.

      Press Toggle to toggle enabled state of the table and textfield.

      Make sure the table is enabled

      * start an edit in a tablecell
      * press toggle (to disable the components)
      * now continue the edit - should not be possible





      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package swt;

      import java.awt.BorderLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JTable;
      import javax.swing.JTextField;
      import javax.swing.WindowConstants;
      import javax.swing.table.AbstractTableModel;
      import javax.swing.table.TableModel;

      public class TableTest extends JFrame {

      private JButton but;
      private JButton rbut;
      private JTable tab;
      private JTextField tex;

      public TableTest() {
      super();
      TableModel dataModel = new AbstractTableModel() {
      public int getColumnCount() { return 3; }
      public int getRowCount() { return 3;}
      public boolean isCellEditable(int row, int col) { return true; }
      public Object getValueAt(int row, int col) { return new Integer(row*col); }
      };
      setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      but=new JButton("Toggle");
      rbut=new JButton("Real Toggle");
      tab=new JTable(dataModel);

      tex=new JTextField("Tekst");
      setLayout(new BorderLayout());
      add(but, BorderLayout.EAST);
      add(rbut, BorderLayout.WEST);
      add(tab, BorderLayout.CENTER);
      add(tex, BorderLayout.SOUTH);
      but.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      boolean b=tab.isEnabled();
      tab.setEnabled(!b);
      tex.setEnabled(!b);
      }
      });
      rbut.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      boolean b=tab.isEnabled();
      tab.setEnabled(!b);
      if (tab.getCellEditor()!=null) {
      tab.getCellEditor().cancelCellEditing();
      }
      tex.setEnabled(!b);
      }
      });
      pack();
      }
      /**
      * @param args
      */
      public static void main(String[] args) {
      // TODO Auto-generated method stub
      new TableTest().setVisible(true);
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :

      Explicitly call cancelCellEditing if active.

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: