-
Bug
-
Resolution: Duplicate
-
P3
-
8u25
-
x86
-
windows_8
FULL PRODUCT VERSION :
java version "1.8.0_25" (build 1.8.0_25-b18)
ADDITIONAL OS VERSION INFORMATION :
Windows 8.1 Pro
A DESCRIPTION OF THE PROBLEM :
If an editable JComboBox is used as a cell editor within a JTable, and the user makes a change then moves off the cell, using either the tab key or by clicking on another cell, the change is lost. This is inconsistent with a normal cell where edits are not lost when the user moves to a new cell using tab or mouse clicking.
Currently, the only way to accept an edit of an editable JComboBox within a JTable is to first press enter. Then press tab (or mouse click) to move to another cell.
This problem was reported in 1999-2001 and was supposedly fixed but it appears to have resurfaced.
Refer to:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4275046
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4336350
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Note: The sample code shown in bug “4275046” demonstrates the problem.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
---- ComboEditorTest.java ------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
public class ComboEditorTest extends JFrame {
// fill in table values
public static String[] colNames = {
"no.", "methode", "id 1", "id2", "sample weight", "unit"
};
public static Object[][] data = {
{
new Integer(1), "chlorid", "123456789012345678901234",
"4711 - 0815", new Float(7.2348), "g"
}, {
new Integer(2), "chlorid", "123456789012345678901234",
"4711 - 0815", new Float(7.2348), "g"
}, {
new Integer(3), "chlorid", "123456789012345678901234",
"4711 - 0815", new Float(7.2348), "g"
}
};
public ComboEditorTest() {
JTable table = new JTable(data, colNames);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setPreferredSize(new Dimension(450, 100));
getContentPane().add(scrollPane);
// use a combo box as cell renderer for the 2nd column
JComboBox cb = new JComboBox();
cb.setEditable(true);
cb.addItem("chlorid");
cb.addItem("HCl");
cb.addItem("water");
cb.addItem("NaCl");
cb.addItem("crystall water");
cb.addItem("anything");
TableColumn col = table.getColumnModel().getColumn(1);
col.setCellEditor(new DefaultCellEditor(cb));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
}
public static void main(String[] args) {
ComboEditorTest test = new ComboEditorTest();
test.pack();
test.setVisible(true);
}
}
---- end ComboEditorTest.java ------
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Press enter to accept the changes then press tab to move off the cell
java version "1.8.0_25" (build 1.8.0_25-b18)
ADDITIONAL OS VERSION INFORMATION :
Windows 8.1 Pro
A DESCRIPTION OF THE PROBLEM :
If an editable JComboBox is used as a cell editor within a JTable, and the user makes a change then moves off the cell, using either the tab key or by clicking on another cell, the change is lost. This is inconsistent with a normal cell where edits are not lost when the user moves to a new cell using tab or mouse clicking.
Currently, the only way to accept an edit of an editable JComboBox within a JTable is to first press enter. Then press tab (or mouse click) to move to another cell.
This problem was reported in 1999-2001 and was supposedly fixed but it appears to have resurfaced.
Refer to:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4275046
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4336350
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Note: The sample code shown in bug “4275046” demonstrates the problem.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
---- ComboEditorTest.java ------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
public class ComboEditorTest extends JFrame {
// fill in table values
public static String[] colNames = {
"no.", "methode", "id 1", "id2", "sample weight", "unit"
};
public static Object[][] data = {
{
new Integer(1), "chlorid", "123456789012345678901234",
"4711 - 0815", new Float(7.2348), "g"
}, {
new Integer(2), "chlorid", "123456789012345678901234",
"4711 - 0815", new Float(7.2348), "g"
}, {
new Integer(3), "chlorid", "123456789012345678901234",
"4711 - 0815", new Float(7.2348), "g"
}
};
public ComboEditorTest() {
JTable table = new JTable(data, colNames);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setPreferredSize(new Dimension(450, 100));
getContentPane().add(scrollPane);
// use a combo box as cell renderer for the 2nd column
JComboBox cb = new JComboBox();
cb.setEditable(true);
cb.addItem("chlorid");
cb.addItem("HCl");
cb.addItem("water");
cb.addItem("NaCl");
cb.addItem("crystall water");
cb.addItem("anything");
TableColumn col = table.getColumnModel().getColumn(1);
col.setCellEditor(new DefaultCellEditor(cb));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
}
public static void main(String[] args) {
ComboEditorTest test = new ComboEditorTest();
test.pack();
test.setVisible(true);
}
}
---- end ComboEditorTest.java ------
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Press enter to accept the changes then press tab to move off the cell
- duplicates
-
JDK-8072767 DefaultCellEditor for comboBox creates ActionEvent with wrong source object
- Resolved
- relates to
-
JDK-4275046 JTable does not handle editable JComboBox as cell editor correctly
- Resolved
-
JDK-8032878 Editable combos in table do not behave as expected
- Resolved
-
JDK-8243282 Enter some text and click into another cell,it reverts to the old, unedited text
- Closed
-
JDK-4336350 JComboBox DefaultCellEditor problems
- Closed