I found it easier to put a keyup event on the input field and checking the data that is entered. If it does not validate I do the following:
1. I disable the ok button
2. I show an error message
the "netbeans" way to do it and for me this is the most user friendly, and the easiest to implement.
Hello Friends,
That is not ficiable for me.Actuall that JTextField is already use Document listener and focus listener and HexFormatter.
In sort i am making a JFormattedTextField as Hex JTextField which will validate only 0-9 and a-f And A-F will be valide entry and remail it will ignore.
I have made that one .but we require output like
45 56 89 a4 59
Here space will generate by programmer not user,he will enter only data....so i want remove space bar
i have used this way but that is not working
KeyMap space=txtBox.getKeymap()
KeyStroke stroke=KeyStroke.getKeyStroke
(KeyEvent.VK_SPACE,0);
space.removeKeyStrokeBinding(stroke);
but this not working
JTextField textField = new JTextField();
textField.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
e.consume();
}
}
});
> HI,
> That is also not working.....still space is
> generating by space bar
Yes it's generated but is immediately consumed in the event listener. If you have another listener which is firing before the key down event then you will have to check if the source is the space bar and consume it there