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]
# 1
char upperChar = Character.toUpperCase(e.getKeyChar());Like that?
CaptainMorgan08a at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...
# 2
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.
DrLaszloJamfa at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...
# 3

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

calvino_inda at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...
# 4
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.
DrClapa at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...
# 5
i tried before and it doesn't work (i had a mistake and now i see where!!)Thanks a lot!! :)wow, how fast U've wrote the answers :)thanks for allnull
thud_Mikea at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...
# 6

> 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)

thud_Mikea at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...
# 7

> > 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

DrLaszloJamfa at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...
# 8
yea, indeed :)thanks again!greetingsthud
thud_Mikea at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...
# 9
Once again: KeyListener -- not needed to solve the problem.
DrLaszloJamfa at 2007-7-12 0:13:13 > top of Java-index,Java Essentials,Java Programming...