-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
1.3.1_08, 1.4.1, 1.4.1_03, 1.4.2
-
x86
-
windows_98, windows_xp
Name: jk109818 Date: 08/17/2003
FULL PRODUCT VERSION :
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
FULL OS VERSION :
Windows 98 [Version 4.10.2222]
A DESCRIPTION OF THE PROBLEM :
An editable JComboBox will replace whatever users entered or selected if the model underlying it changed. This only happens for standalone JComboBox, not inside a table. If a table columns use an editable combobox and the combobox model change then whatever was entered selected in the table's cells will not be changed.
This is a big problem. One senario can be this: if a user needs to enter an input, an editable combobox was used so that some suggestions could be made (by the drop down). The list of suggestion can be changed on the fly. User enter some value into the combo box, then go down and enter other type of information and click submit. Users does not know that while doing something else, the combobox data was change and the users' input no longer valid because the suggestion list was updated elsewhere.
This does not need to be multi-threaded environment for it to happen. If users go to a different view (such as a different tab) and do something that trigger the change of the suggestion list, and go back and finish the form. The combobox value will be changed.
I think this is a very commonly used component and a very serious problem if not fixed quickly.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Compile and run the code
2) Enter "Hello" into the combobox
3) Click on the button to the right
4) Select "2" from the combobox
5) Click on the button to the right.
EXPECTED VERSUS ACTUAL BEHAVIOR :
If the model of an editable combobox change, the data entered or selected by user to the combobox should not be changed.
The data was changed.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
public class ComboBoxError extends javax.swing.JFrame {
ComboBoxModel mymodel;
/** Creates new form ComboBoxError */
public ComboBoxError() {
initComponents();
mymodel = new ComboBoxModel();
mymodel.update();
this.jComboBox1.setModel(mymodel);
}
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
getContentPane().setLayout(null);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jComboBox1.setEditable(true);
getContentPane().add(jComboBox1);
jComboBox1.setBounds(70, 100, 200, 25);
jButton1.setText("Change Model");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(310, 100, 120, 26);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// Add your handling code here:
mymodel.update();
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new ComboBoxError().show();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
// End of variables declaration
}
class ComboBoxModel extends DefaultComboBoxModel{
public void update(){
int i;
this.removeAllElements();
for(i = 0; i < 6; i++){
this.addElement("" + i);
}
}
}
---------- END SOURCE ----------
(Incident Review ID: 184772)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
FULL OS VERSION :
Windows 98 [Version 4.10.2222]
A DESCRIPTION OF THE PROBLEM :
An editable JComboBox will replace whatever users entered or selected if the model underlying it changed. This only happens for standalone JComboBox, not inside a table. If a table columns use an editable combobox and the combobox model change then whatever was entered selected in the table's cells will not be changed.
This is a big problem. One senario can be this: if a user needs to enter an input, an editable combobox was used so that some suggestions could be made (by the drop down). The list of suggestion can be changed on the fly. User enter some value into the combo box, then go down and enter other type of information and click submit. Users does not know that while doing something else, the combobox data was change and the users' input no longer valid because the suggestion list was updated elsewhere.
This does not need to be multi-threaded environment for it to happen. If users go to a different view (such as a different tab) and do something that trigger the change of the suggestion list, and go back and finish the form. The combobox value will be changed.
I think this is a very commonly used component and a very serious problem if not fixed quickly.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Compile and run the code
2) Enter "Hello" into the combobox
3) Click on the button to the right
4) Select "2" from the combobox
5) Click on the button to the right.
EXPECTED VERSUS ACTUAL BEHAVIOR :
If the model of an editable combobox change, the data entered or selected by user to the combobox should not be changed.
The data was changed.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
public class ComboBoxError extends javax.swing.JFrame {
ComboBoxModel mymodel;
/** Creates new form ComboBoxError */
public ComboBoxError() {
initComponents();
mymodel = new ComboBoxModel();
mymodel.update();
this.jComboBox1.setModel(mymodel);
}
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
getContentPane().setLayout(null);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jComboBox1.setEditable(true);
getContentPane().add(jComboBox1);
jComboBox1.setBounds(70, 100, 200, 25);
jButton1.setText("Change Model");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(310, 100, 120, 26);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// Add your handling code here:
mymodel.update();
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new ComboBoxError().show();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
// End of variables declaration
}
class ComboBoxModel extends DefaultComboBoxModel{
public void update(){
int i;
this.removeAllElements();
for(i = 0; i < 6; i++){
this.addElement("" + i);
}
}
}
---------- END SOURCE ----------
(Incident Review ID: 184772)
======================================================================