2 Replies Latest reply on Jan 7, 2005 2:42 AM by 807596

    getKeyChar() and backspace

      I have a JTextField with setEditable(false);
      There is a key listener on it and it adds stuff to the JTextField as it's typed but sends text different from what the user types in (this is just for fun, I currently have it display moron as they type each key but I still store the password). Anyway, the problem arises with the backspace key. No matter what key I type e.getKeyCode() returns 0. I assume that has to do with the textfield not being editable but not sure. So I have used e.getKeyChar() but I don't know what backspace is returned as. If I display it with System.out.println(e.getKeyChar()) it just leaves a blank line. If I put it in a JTextArea it comes out as a rectangle (like a straight line 0 on digital clocks without each individual line). Anyway, is there a way to actually compare the backspace key to a key on the keyboard (I have tried CHAR_UNDEFINED but that doesn't work either) I can type in?