Disable character removing keys in a JavaFX TextField
<p>The title pretty much says it all. I need to disable character-removing keys in a JavaFX TextField. By character-removing keys, I mean DEL and SUPPR.</p>

<p>Right now, this is what I have:</p>

<pre><code>mytextfield.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler&lt;KeyEvent&gt;() {
        public void handle(KeyEvent event) {          
            if (event.getCharacter().matches("[0-9]")) {
                // some stuff that works perfectly here
            }
            event.consume(); // to cancel everything but 0-9 keys
        }
    });
</code></pre>

<p>But for some reason, even though the event gets consumed, the end character still gets deleted when pressing delete.</p>

<p>Thanks for your time!</p>