JDK-4887999 : JComboBox CellEditor causes JTable to lose focus after editing
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0,1.4.1,1.4.1_03,1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2003-07-09
  • Updated: 2004-10-13
  • Resolved: 2004-09-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 betaFixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Name: jk109818			Date: 07/09/2003


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


FULL OS VERSION :
Windows XP Home Edition

A DESCRIPTION OF THE PROBLEM :
Under JDK 1.4.1_02 or higher, editing a cell that uses an editable combobox editor by selecting an item from the dropdown and pressing TAB or entering text into the combobox and pressing TAB causes focus to leave the table and move to the first component on the same container capable of getting focus.  If you press F2 to end editing of the combobox, the table will retain focus, if not, focus will be lost. If the combobox editor is not "editable" (i.e. setEditable(true) has not been called) and an item is selected from it's dropdown, the table does not lose focus.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile and run the included source code under JDK 1.4.1_02 or higher.  When the JFrame appears, click on a cell in the first column of the table ("Genre"), open the dropdown list, select an item from the list, and press TAB.  The second column of the table will be highlighted, but the cursor will move to the combobox preceding the table.  If you press F2 to end editing, the table will retain focus.  If you don't the table will lose focus.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After editing the combobox in the first column of the table by selecting an item from the list and pressing TAB, I was expecting focus to move to the second column of the table, where I could begin editing that cell.
ACTUAL -
After editing the combobox in the first column of the table and pressing TAB, focus moves to the combobox that is outside of the table.  Any typing will appear in that combobox.

REPRODUCIBILITY :
This bug can be reproduced always.

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

class IAMATEST extends JPanel {

public IAMATEST() {

String table_data[][] = { {"Comedy", "Kindergarten Cop", "1990"},
{"SciFi", "Total Recall", "1990"},
{"Action", "Eraser", "1996"} };

String column_headers[] = {"Genre", "Title", "Year"};

String combo_items[] = {"Stallone","Schwarzenegger"};

JComboBox combo_actors = new JComboBox(combo_items);
combo_actors.setEditable(true);
JTable tbl_movies = new JTable(new DefaultTableModel(table_data, column_headers));
tbl_movies.setColumnSelectionAllowed(false);
tbl_movies.setRowSelectionAllowed(false);
tbl_movies.setCellSelectionEnabled(true);
tbl_movies.setRowHeight(25);

testcomboeditor editor1 = new testcomboeditor();
testtexteditor editor2 = new testtexteditor();
testtexteditor editor3 = new testtexteditor();
tbl_movies.getColumn("Genre").setCellEditor(editor1);
tbl_movies.getColumn("Title").setCellEditor(editor2);
tbl_movies.getColumn("Year").setCellEditor(editor3);

JScrollPane jsp = new JScrollPane();
jsp.getViewport().add(tbl_movies);
jsp.setSize(600, 250);

this.add(combo_actors);
this.add(jsp);

}


public static void main(String args[]) {
JFrame jf = new JFrame();
Container c = jf.getContentPane();
c.add(new IAMATEST());
jf.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
} );

jf.setSize(800, 400);
jf.setVisible(true);
}
}


class testcomboeditor extends AbstractCellEditor implements TableCellEditor
{
JComboBox this_combo;
String[] combo_items = {"Action", "Comedy", "SciFi"};

public testcomboeditor() {
this_combo = new JComboBox(combo_items);
this_combo.setEditable(true);
}

public Component getTableCellEditorComponent(JTable tbl, Object value, boolean isSelected, int row, int column) {
this_combo.setSelectedItem(value.toString());
return this_combo;
}

public Object getCellEditorValue() {
return this_combo.getSelectedItem();
}
}


class testtexteditor extends AbstractCellEditor implements TableCellEditor {

JTextField this_textfield;

public testtexteditor() {
this_textfield = new JTextField();
}

public Component getTableCellEditorComponent(JTable tbl, Object value, boolean isSelected, int row, int column) {
this_textfield.setText(value.toString());
return this_textfield;
}

public Object getCellEditorValue() {
return this_textfield.getText();
}
}

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

CUSTOMER SUBMITTED WORKAROUND :
I added a cellEditorListener to the combobox editor for the first column of the table and in it called tbl_movies.requestFocus().
(Review ID: 187099) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang FIXED IN: mustang INTEGRATED IN: mustang
14-09-2004

EVALUATION Name: pzR10082 Date: 07/11/2003 Looks like pressing tab switches focus between combobox and table, not between table cells. Worked differently in 1.3. ###@###.### ======================================================================
14-09-2004