Le 30/05/2011 10:55, vsalaun@users.chorem.org a écrit :
Author: vsalaun
private static final long serialVersionUID = 1L; private static DateTableCellEditor editor; private boolean keyPressed; + private Date date;
/** * constructor @@ -69,12 +71,34 @@ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (value instanceof Date) { datePicker.setDate((Date) value); + date = (Date) value; } return datePicker; }
@Override public Object getCellEditorValue() { + if (!datePicker.getEditor().getText().isEmpty()) { + String[] str = datePicker.getEditor().getText().split("/"); + //day + if (str.length > 0) { + if (str[0].contains(" ")) { + String[] string = str[0].split(" "); + date = DateUtils.setDays(date, Integer.valueOf(string[1])); + } else { + date = DateUtils.setDays(date, Integer.valueOf(str[0])); + } + } + //month + if (str.length > 1) { + date = DateUtils.setMonths(date, Integer.valueOf(str[1])-1); + } + //year + if (str.length > 2) { + date = DateUtils.setYears(date, Integer.valueOf(str[2])); + } + } + datePicker.setDate(date);
Ca manque surrement encore de commentaire... encore... :) Mais quel est le but d'une telle manipulation. date et datePicker.getValue référence la même valeur. A quoi sert le découpage à la main de la date alors que c'est le but du composant ? -- Éric Chatellier <chatellier@codelutin.com> Tel: 02.40.50.29.28 http://www.codelutin.com