Salve,
ho messo il seguente keylistener all'interno di una jtextfield in modo da non accettare il numero 0 in scrittura.

codice:
KeyListener k=new KeyListener() {

            public void keyTyped(KeyEvent e) {
               // throw new UnsupportedOperationException("Not supported yet.");
            }

            public void keyPressed(KeyEvent e) {
                int evt=e.getKeyCode();
                char dd=e.getKeyChar();
                
               
                if (dd==KeyEvent.VK_0) {                    
                    String testo="";                    
                    StringTokenizer arch=new StringTokenizer(Text.getText(),"0");
                    while (arch.hasMoreTokens()) testo=testo+arch.nextToken();                                        
                    Text.setText(testo);
                    
                }
            }

            public void keyReleased(KeyEvent e) {
                //throw new UnsupportedOperationException("Not supported yet.");
            }
        };        
        Text.addKeyListener(k);

il problema è che il metodo viene richiamato ma lo zero continua a comparire ugualmente nella jtextfield , ad esempio se digito "12340" il textfield dovrebbe diventare "1234" ma rimane sempre "12340" se continuo a digitare ,ad esempio "12340560" il testo diventa "1234560"

insomma non mi cancella mai l'ultimo zero inserito, come mai?