Win a copy of Learning Java by Building Android Games this week in the Android 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

JCOMBO Box traversal problem  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable with 3 columns. The columns are radio button, jlabel and Jcombo Box. Each of them are retrieved using renderer. The first two columns are generated using super.getRendererComponent method. The combo box for last column is generated explicitly in the getRendererComponent method of DefaultCellRendererImpl class.

I give a simple layout of the program i have here.

// renderer for the 1st column of my table. It extends DefaultTableCellRenderer. We create a JRadiobutton in the getTableCellRendererComponent() method and return that component. So this column will be showed as radio button
final TableCellRenderer Col1Renderer = new RadioBtnTableCellRenderer();

//renderer for 2nd and 3rd column. It extends DefaultTableCellRenderer. In the getTableCellRendererComponent() method, we call super.getTableCellRendererComponent() method if it is 2nd column (It displays like a label) and we create a JcomboBox and return the component if it is a 3rd column.
final TableCellRenderer nameValRenderer = new NameValueCellRenderer();

// This model is returning values for each column appropriately
//Here column 0(1st) and 2(3rd) is marked as editable
CustLayersTableModel tm = new CustLayersTableModel();

// Set-up the JTable with custom renderers
custLayersTable = new JTable(tm)
{
// Override the cell render to show the layers name, value
// after tip layer as disabled
public TableCellRenderer getCellRenderer(int row, int column)
{
if ( column == LAYER_VAL_COL ||
column == LAYER_NAME_COL)
{
return nameValRenderer;
}
else if ( column == TIP_LAYER_COL )
{
return tipRenderer;
}

return super.getCellRenderer(row, column);
}
};

TableColumnModel colModel = custLayersTable.getColumnModel();

//The 1st column is configured with cellEditor class TipLayerCellEditor. This class extends AbstractCellEditor and implements TableCellEditor. In the getTableCellEditorComponent method we are creating a radiobutton with the values and returning the component.
TableColumn tipCol = colModel.getColumn(0);
tipCol.setCellEditor(new TipLayerCellEditor());

//The 3nd column is configured with cellEditor class LayerValueCellEditor. This class extends AbstractCellEditor and implements TableCellEditor. In the getTableCellEditorComponent method we are creating a comboBox with some values and returning the component.
TableColumn valCol = colModel.getColumn(2);
valCol.setCellEditor(new LayerValueCellEditor(this));

This code is working fine. We are able to edit the comboBox by clicking on that comboBox. When we do tab from other cells the focus is not coming to the combo Box to edit. Even after clicking the comboBox we can select the values only through mouse not by keyboard.

Please help me to bring the focus to the combo box of the third column
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!