getKeyCode & getKeyChar
hello,
i've got sth like this:
publicvoid keyPressed(KeyEvent e){
int KeyUpper = KeyEvent.VK_SHIFT + e.getKeyCode();
//...
}
and i wanna change int KeyUpper at the char (i want to display in JTextField char)
for example: User press 'a' and i want to change that letter on capital letter 'A' so i've thought that i do something that U see (KeyEvent.VK_SHIFT + e.getKeyCode();), but as I said i don't know how change 'int' to 'char' (<- only that, the rest i'll do on my own :))
I apologize for my poor english :)
thud
Message was edited by:
thud_Mike
Message was edited by:
thud_Mike
null
[886 byte] By [
thud_Mikea] at [2007-11-27 1:23:31]

look at the ascii table:
http://game-editor.com/tutorials/images/ascii.jpg
you can see that upper chars are 32 before lower chars (ex: a is 97 and A is 65 --> 97 - 65 = 32) so maybe you should just make:
public void keyPressed(KeyEvent e) {
int keyUpper = e.getKeyCode() - 32;
char keyUpperAsChar = (char) keyUpper;
}
Message was edited by:
calvino_ind
If you want to have a JTextField that forces the user's input to appear in all upper-case then there's a better way to do it than messing about with key codes. And even better, the entire code for it is already in the API documentation for JTextField! Have a look there.
> Is the bottom line here that you want a text field to
> act as though the CAPS LOCK is set?
>
> If so, I would write a custom Document or a
> DocumentFilter instead.
Yeah i want to do exactly that. I will be gratefull if U do this :) (the user have to see only capital letters even he will be typing small letters)
> > Is the bottom line here that you want a text field
> to
> > act as though the CAPS LOCK is set?
> >
> > If so, I would write a custom Document or a
> > DocumentFilter instead.
>
> Yeah i want to do exactly that. I will be gratefull
> if U do this :) (the user have to see only
> capital letters even he will be typing small letters)
DrClap has already written where to look: http://java.sun.com/javase/6/docs/api/javax/swing/JTextField.html