class TableEditor extends AbstractCellEditor implements TableCellEditor {
JTextField textField;
public TableEditor() {
textField = new JTextField();
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,
int row, int col)
{
textField.setText(String.valueOf(value));
return textField;
}
public Object getCellEditorValue() {
String s = textField.getText();
if(!s.equals("")){
try {
int i = Integer.parseInt(s);
}
catch(NumberFormatException nfe) {
System.out.println("worng Entry: " + nfe.getMessage());
JOptionPane.showMessageDialog(null,"Data Input Error, Plz Inter Integer value","Error",JOptionPane.ERROR_MESSAGE);
return Integer.valueOf(0);
}
}
else{
JOptionPane.showMessageDialog(null,"Data Input Error, Plz Inter Integer value","Error",JOptionPane.ERROR_MESSAGE);
return Integer.valueOf(0);
}
return Integer.valueOf(s);
}
public boolean stopCellEditing() {
Integer i = ((Integer)getCellEditorValue());
if(i==0||i>0) {
fireEditingCanceled();
return false;
}
return super.stopCellEditing();
}
}
-----------------------------------------
Read for more information with example at:
http://www.roseindia.net/java/example/java/swing/Thanks