When using the method below, it returns false, even when the correct value is entered in the JTable cell. What could be the error?
boolean checkTime(JTable table,int indexRow,int indexColOfValue){//возвращает правильность формата необходимого столбца времени TableModel tableModel= table.getModel(); //используем модель таблицы TimeZone tz = TimeZone.getTimeZone("Europe/Moscow"); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); dateFormat.setLenient(false); try { dateFormat.parse(tableModel.getValueAt(indexRow, indexColOfValue).toString()); } catch (ParseException e) { return false; } return true; } The result, after setting the output of the cell value before parse ():
14:12:40 // прошло 11:15:60 // не прошло по условию 11:15:60 // должно пройти, так как менял значение на верное 11:15:60 // должно пройти, так как менял значение на верное Call this method in the list box:
table.getColumnModel().getColumn(3). setCellEditor(new DefaultCellEditor(txtFld){ @Override public boolean stopCellEditing() { System.out.println("DefaultCellEditor "+ row+" "+col); if(!checkTime(table, col, row)){ return false; } else return true; } });
System.out.println(tableModel.getValueAt(indexRow, indexColOfValue).toString())and show what will be output to the console. - post_zeewtxtFldis passed toDefaultCellEditorand where is it used internally? - iksuy