Setting an editor

Top  Previous  Next

 

You can set your own editor by calling JTable's following method:

 

public void setDefaultEditor(Class columnClass, TableCellEditor editor);

 

Example: Set a date editor

 

JTable table = new JTable();

DateEditor de = new DateEditor();

table.setDefaultEditor(Date.class, de);

 

Example: Set a TableComboBoxEditor editor

 

String countries[] = new String[] {

       "Greece",

       "Argentina",

       "Germany",

       "Spain",

};

TableCellEditor combo= new com.sciapp.editors.TableComboBoxEditor(countries);

TableColumn countryColumn;

 

countryColumn = table.getColumnModel().getColumn(1);

countryColumn.setCellEditor(combo);