I need a method that allows only certain characters are entered in a jTable.
My jframe is below:
In the columnd "Precedentes" i need that the column accepts only numbers and ",".
A input example that i need:
My validation method of this column is below:
private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {
i = 0;
String carac="0987654321,";
if(!carac.contains(tableModel.getValueAt(i, 3)+"")){
tableModel.consume();// TODO add your handling code here:
}
}
i => It's my line number (it's used in a loop to verify each line). So I go line line by line getting what the user typed in the column "precedentes" and validate with that method.
When i type something that is not a number or "," the columns "Precedente" should not accept.
Error message when i execute my method:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
I think what i need is a mask that accepts only number and ",", but i don't know how to do this to a column of a jTable, i know how to to this with a text field, but the method that i use to validate that in a text field doesn't work in a jtable.