Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Focus traversal problem in JTable

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()
{
super();
this.setLayout( null );
this.setSize( new Dimension(400, 300) );

JTextField ch = new JTextField();
ch.setVisible(true);
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);
custLayersTable.getColumnModel().getColumn(0).
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();
a.setVisible(true);
}
}

// 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);
mComboModel.setSelectedItem(value);
mEditorComp = new JComboBox(mComboModel);
return mEditorComp;
}

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

private DefaultComboBoxModel mComboModel;
private JComboBox mEditorComp;
}
 
ashok rajendran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
For my next trick, I'll need the help of a tiny ad ...
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic