Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Focus traversal problem in JTable

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a check box and a JTable in my swing app. This JTable cells will become a JComboBox when user wants to edit the value. User can edit the cell either by clicking on that or by pressing F2 and UP/DOWN keys.
I want to navigate out from the JTable by pressing ctrl+tab.(Which is prescribed in sun java doc as well). So, when i press ctrl+tab from JTable the focus should come to the check box which is first component (and next component to JTable) in my app.
It does not work for me when my focus is on the JcomboBox. It works only when the focus is on the cell which is not in edit mode, i mean plain JTable cell. (If you press esc/tab key the JComboBox will disappear and your focus will be on plain JTable cell)
Please help me out to get my requirement.

Here is my sample app for you reference.
public class Frame1 extends JFrame
public Frame1()
this.setLayout( null );
this.setSize( new Dimension(400, 300) );

JTextField ch = new JTextField();
ch.setBounds(10, 10, 10, 10);
this.add(ch, null);

DefaultTableModel tmodel = new DefaultTableModel(3, 1);
tmodel.setValueAt("0 0 1",0,0);
tmodel.setValueAt("1 0 1",1,0);
tmodel.setValueAt("2 0 1",2,0);

JTable custLayersTable = new JTable(tmodel);
setCellEditor(new ComboEditor());
custLayersTable.setBounds(new Rectangle(40, 40, 280, 145));
this.add(custLayersTable, null);

public static void main(String[] args)
Frame1 a = new Frame1();

// This is the table cell editor which returns combo box to JTable.
final class ComboEditor extends AbstractCellEditor
implements TableCellEditor
public Component getTableCellEditorComponent(JTable table,
Object value,
boolean isSelected,
int row,
int column)
Vector<String> layerValSet = new Vector<String>();
for(int i=0; i<3; i++)
layerValSet.add(row+" "+column+" "+i);
mComboModel = new DefaultComboBoxModel(layerValSet);
mEditorComp = new JComboBox(mComboModel);
return mEditorComp;

public Object getCellEditorValue()
return mEditorComp.getSelectedItem();

private DefaultComboBoxModel mComboModel;
private JComboBox mEditorComp;
ashok rajendran
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I missed to inform the following in the post..
When i focus is on JComboBox pressing ctrl+tab does not take the focus to anywhere. The only change i can see after pressing ctrl+tab is that the focus lost from the JComboBox, but the JComboBox remains as it was before.
    Bookmark Topic Watch Topic
  • New Topic