Bonjour tout le monde,
Je voudrais empecher la saisie de tout caracteres non HexaDecimal dans une JTable et je ne sais pas comment commencer
merci davance
Version imprimable
Bonjour tout le monde,
Je voudrais empecher la saisie de tout caracteres non HexaDecimal dans une JTable et je ne sais pas comment commencer
merci davance
Je pense que tu doit dénifir ton propre TableCellEditor qui ne valide que l'hexa, ensuite tu le définit comme editor de toutes les colonnes qui t'interessent.
Exemple:
Et voila le principe!Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor { // This is the component that will handle the editing of the cell value JComponent component = new JTextField(); // This method is called when a cell value is edited by the user. public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int vColIndex) { // 'value' is value contained in the cell located at (rowIndex, vColIndex) if (isSelected) { // cell (and perhaps other cells) are selected } // Configure the component with the specified value ((JTextField)component).setText((String)value); // Return the configured component return component; } // This method is called when editing is completed. // It must return the new value to be stored in the cell. public Object getCellEditorValue() { if(isHexa(((JTextField)component).getText())) return ((JTextField)component).getText(); else return ""; } }