-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
7u25
-
x86
-
windows_7
FULL PRODUCT VERSION :
c:\work\JavaTestArea>java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
It is a 64-bit install of the OS using 32-bit version of the JDK.
A DESCRIPTION OF THE PROBLEM :
When using a JSpinner object as a custom cell editor it does not recognize a change in value if the value is manually entered.
Using the spinner incremented/decremented via the scroll keys the new value is accepted. .
If a new value is manually entered and the enter key pressed, the new value is printed after moving off the cell.
The issue is if you double click to active the custom editor, hit the backspace, enter a new value then click to a different cell, the old value is displayed instead of the new.
ADDITIONAL REGRESSION INFORMATION:
c:\work\JavaTestArea>java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the testcase provided which uses JSpinner as a custom editor.
Double click to invoke the edit mode of the JSpinner object.
Delete the existing value.
Insert a new value.
(Do NOT hit enter and do NOT use the arrow keys.)
Use the mouse to click on to the next cell. When this is done the new value is not processed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JSpinner should accept a new value when manually entered without having to use the arrow keys or hitting return.
ACTUAL -
The old value is retained instead of the new value.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error. Wrong data.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Component;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.EventObject;
import javax.swing.AbstractCellEditor;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.SpinnerListModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
import javax.swing.JFrame;
public class MainApp {
public static void main(String[] argv) throws Exception {
MainApp x = new MainApp();
}
JTable table = new JTable();
DefaultTableModel model;
JFrame myFrame = new JFrame();
public MainApp()
{
myFrame.setSize(400, 300);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
model = (DefaultTableModel) table.getModel();
model.addColumn("A", new Object[] { "1","3" });
model.addColumn("B", new Object[] { "2","4" });
String[] values = new String[] { "1", "2", "3" , "4", "5"};
TableColumn col = table.getColumnModel().getColumn(0);
col.setCellEditor(new SpinnerEditor(values));
myFrame.add(table);
myFrame.setVisible(true);
}
}
class SpinnerEditor extends AbstractCellEditor implements TableCellEditor {
final JSpinner spinner = new JSpinner();
public SpinnerEditor(String[] items) {
spinner.setModel(new SpinnerListModel(Arrays.asList(items)));
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
int row, int column) {
spinner.setValue(value);
return spinner;
}
public boolean isCellEditable(EventObject evt) {
if (evt instanceof MouseEvent) {
return ((MouseEvent) evt).getClickCount() >= 2;
}
return true;
}
public Object getCellEditorValue() {
System.out.println("Spinner value = " + spinner.getValue());
return spinner.getValue();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
There isn't a work-around because by the time any associated event is captured the new value is already gone.
c:\work\JavaTestArea>java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
It is a 64-bit install of the OS using 32-bit version of the JDK.
A DESCRIPTION OF THE PROBLEM :
When using a JSpinner object as a custom cell editor it does not recognize a change in value if the value is manually entered.
Using the spinner incremented/decremented via the scroll keys the new value is accepted. .
If a new value is manually entered and the enter key pressed, the new value is printed after moving off the cell.
The issue is if you double click to active the custom editor, hit the backspace, enter a new value then click to a different cell, the old value is displayed instead of the new.
ADDITIONAL REGRESSION INFORMATION:
c:\work\JavaTestArea>java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the testcase provided which uses JSpinner as a custom editor.
Double click to invoke the edit mode of the JSpinner object.
Delete the existing value.
Insert a new value.
(Do NOT hit enter and do NOT use the arrow keys.)
Use the mouse to click on to the next cell. When this is done the new value is not processed.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JSpinner should accept a new value when manually entered without having to use the arrow keys or hitting return.
ACTUAL -
The old value is retained instead of the new value.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error. Wrong data.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Component;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.EventObject;
import javax.swing.AbstractCellEditor;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.SpinnerListModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
import javax.swing.JFrame;
public class MainApp {
public static void main(String[] argv) throws Exception {
MainApp x = new MainApp();
}
JTable table = new JTable();
DefaultTableModel model;
JFrame myFrame = new JFrame();
public MainApp()
{
myFrame.setSize(400, 300);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
model = (DefaultTableModel) table.getModel();
model.addColumn("A", new Object[] { "1","3" });
model.addColumn("B", new Object[] { "2","4" });
String[] values = new String[] { "1", "2", "3" , "4", "5"};
TableColumn col = table.getColumnModel().getColumn(0);
col.setCellEditor(new SpinnerEditor(values));
myFrame.add(table);
myFrame.setVisible(true);
}
}
class SpinnerEditor extends AbstractCellEditor implements TableCellEditor {
final JSpinner spinner = new JSpinner();
public SpinnerEditor(String[] items) {
spinner.setModel(new SpinnerListModel(Arrays.asList(items)));
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
int row, int column) {
spinner.setValue(value);
return spinner;
}
public boolean isCellEditable(EventObject evt) {
if (evt instanceof MouseEvent) {
return ((MouseEvent) evt).getClickCount() >= 2;
}
return true;
}
public Object getCellEditorValue() {
System.out.println("Spinner value = " + spinner.getValue());
return spinner.getValue();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
There isn't a work-around because by the time any associated event is captured the new value is already gone.