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

Cell editing does not complete when JTable loses focus

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.3.1, 1.4.0
    • Fix Version/s: 1.4.1
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      hopper
    • CPU:
      generic, x86, sparc
    • OS:
      generic, solaris_2.6, solaris_8, windows_95, windows_98, windows_nt
    • Verification:
      Verified

      Description



      Name: gm110360 Date: 09/17/2001


      java version "1.4.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
      Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)

        To reproduce the problem, run the attached program, enter data into a cell, and
      then click on another UI component. The data that was entered is now gone.
      This happens consistently the first time data is entered into a cell and the
      table loses focus before the edit operation is completed.

      Repeat the operation, double-click on a cell, enter some data, and then click
      on another UI component. This time, the data remains, but the CellEditor
      remains active and the edit operation is not completed. If you select the
      Print Function, it is apparent that the entered data was never saved.

      The second aspect of the problem was reported against 1.2.2 & 1.4 beta. It
      also exists in 1.3. Bugs 4460382 is closed and the problem is reported fixed
      in merlin - Beta 2. Well, apparently not. In fact, the problem with the
      CellEditor has another aspect to it right now.

      I have not been able to get any of the supposed workarounds to work. There
      have been comments that this would get fixed in 1.4 - my fear is that since it
      has been closed (I believe in error), the problem will slip through the cracks.

      Thanks.

      import javax.swing.*;
      import javax.swing.table.*;
      import java.awt.*;
      import java.awt.event.ActionEvent;

      public class FrameNTable extends JFrame {
        JTable table, table2, table3;
        String[] columnNames = {"String", "String", "String"};
        Object[][] data = { {null, null, null},
                            {null, null, null},
                            {null, null, null} };
        public FrameNTable() {
      String version = System.getProperty("java.specification.version");
           System.out.println("Java specification version = " + version );
              createGUI();
              pack();
              setVisible(true);
        }
        private void createGUI() {
      JPanel contentPane = new JPanel();
      setContentPane(contentPane);
          contentPane.setLayout(new BorderLayout());
       
           // create the JTable
           TableModel tableModel = new MyTableModel();
      table = new JTable(tableModel);
      contentPane.add(table, BorderLayout.CENTER);

      // add some other components for variety
              JPanel panel = new JPanel();
              JTextField textField1 = new JTextField("Field 1");
              JTextField textField2 = new JTextField("Field 2");
              panel.add(textField1);
              panel.add(textField2);
      JButton button = new JButton("Print");
      panel.add(button);
              
              contentPane.add(panel, BorderLayout.SOUTH);

         
              button.addActionListener(new java.awt.event.ActionListener() {
               public void actionPerformed(ActionEvent e) {
      System.out.println();
                       for (int i = 0; i < 3; i++) {
               for (int j = 0; j < 3; j++) {
               System.out.print(data[i][j] + " ");
               }
               System.out.println();
               }
                     }
      });
        }
        
        class MyTableModel extends AbstractTableModel {

          public MyTableModel () {
          }
          public int getColumnCount() {
             return columnNames.length;
          }
          public int getRowCount() {
             return data.length;
          }
          public String getColumnName(int col) {
             return columnNames[col];
          }
          public Object getValueAt(int row, int col) {
            return data[row][col];
          }
          public void setValueAt(Object value, int row, int col) {
             data[row][col] = value;
          }
          public Class getColumnClass(int col) {
             return java.lang.String.class;
          }
          public boolean isCellEditable(int row, int col) {
              return true;
          }
        }
        public static void main (String[] args) {
          FrameNTable frame = new FrameNTable();
        }
      }
      (Review ID: 132040)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmcduffisunw Dale Mcduffie (Inactive)
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: