Ho necessità di limitare l'inserimento ai soli numeri interi in un jtextfield, ho fatto così:
Il problema è che vorrei permettere il backspace nel caso l'utente sbagli ad inserire il numero ma così come ho fatto non va...nel senso che se premo il backspace lo riconosce come "errore"...dove hos bagliato?codice:private void tablesNumberKeyPressed(java.awt.event.KeyEvent evt) { if (!(evt.getKeyChar() + "" + java.awt.event.KeyEvent.VK_BACK_SPACE).matches ("[0-9]+$")) { tablesNumber.setText(""); JOptionPane.showMessageDialog (null , "Devi inserire un numero intero!" ); } }
Grazie!