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

REGRESSION: calling stopCellEditing() does not set value after first time

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • client-libs



      Name: gm110360 Date: 04/18/2002


      FULL PRODUCT VERSION :
      New:
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      Previous:
      java version "1.3.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
      Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)

      FULL OPERATING SYSTEM VERSION : SunOS venus 5.8
      Generic_108528-06 sun4u sparc SUNW,Sun-Blade-100


      A DESCRIPTION OF THE PROBLEM :
      I recently just upgraded to JDK 1.4 from JDK 1.3.1 and I
      noticed this descrepancy in behaviour right away:

      I have a JTable with editable cells. The user can type some
      text into the JTextFields and then hit a button on the same
      JPanel to submit these values.

      In order allow the text changes without requiring the user
      to explicitly hit "Return" after every cell change, I call
      TableCellEditor's stopCellEditing() to commit the values.

      But for some reason, in JDK 1.4 (it works fine when I run
      using JDK 1.3 with the same .class files) ONLY after the
      first submit, the data entered in the JTextFields would not
      be saved, unless the user explicitly hits "Return" after
      entering the text.

      See test program code below.

      REGRESSION. Last worked in version 1.3.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.Create a JTable with editable cells
      2.Type in some text, do NOT press enter after typing
      3.Call stopCellEditing() from TableCellEditor
      4.Retrieve the value from the JTable using getValueAt()
      5.Print out the value


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      In JDK 1.4: After the first stopCellEditing(), if you try
      to retrieve the value from JTable using getValueAt(), it
      will be null, no value is set.

      Subsequent calls WILL work however. This only happens after
      the first time the JTable is created.

      In JDK 1.3.1: Even after the first call, the value typed in
      can be retrieved.

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;
      import javax.swing.*;
      import javax.swing.table.*;

      public class TestC implements ActionListener
      {
         JTable table;
         JButton button;
         JPanel panel;

         public TestC()
         {
             panel = new JPanel(new BorderLayout());
             DefaultTableModel dtm = new DefaultTableModel(1, 1);
             table = new JTable(dtm);
             TableColumn col = table.getColumnModel().getColumn(0);
             JTextField text = new JTextField();
             col.setCellEditor(new DefaultCellEditor(text));

             button = new JButton("OK");
             button.addActionListener(this);

             panel.add(BorderLayout.CENTER, table);
             panel.add(BorderLayout.SOUTH, button);

             JFrame frame = new JFrame();
             frame.getContentPane().add(panel);
             frame.setBounds(100,100,100,100);
             frame.setVisible(true);
         }

         public void actionPerformed(ActionEvent e)
         {
             Object obj = e.getSource();
             if (obj == button)
             {
                TableColumn col = table.getColumnModel().getColumn(0);
                TableCellEditor tce = col.getCellEditor();

                if (tce != null)
                {
                    tce.stopCellEditing();
                    System.out.println("Cell val: " +
      (String)tce.getCellEditorValue());
                }
             }
             String value = (String)table.getValueAt(0, 0);
             System.out.println("User Input Value is: " + value);
         }

         static public void main(String[] args)
         {
             TestC test = new TestC();
         }
      }

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

      CUSTOMER WORKAROUND :
      Have to explicitly call

      table.setValueAt(tce.getCellEditorValue(), row, column);

      to ensure the value is entered into the JTable's model.

      Release Regression From : 1.3.1_03
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Review ID: 145298)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: