Skip to main content

bug with JTextPane in java 1.7.0

5 replies [Last post]
ixanos
Offline
Joined: 2008-12-06
Points: 0

I assume the following problem is a bug.
When typing the character ' in a JTextPane the cursor jumbs to positions and types it.
This missbehaviour is reproducable also with TextComponentDemo.java as published on
http://java.sun.com/docs/books/tutorial/uiswing/examples/components/inde...

I run this demo using

Java Web Start 1.7.0-ea
Using JRE version 1.7.0-ea-b81 Java HotSpot(TM) Client VM

you can also reproduce the same by simply typing this character in the given demo pane.

here the details of the character on my machine:

*** KEY TYPED ***[getID =401][400]
[getKeyCode=222]
[getKeyText=Quote]
[getKeyChar=']
[getExtendedKeyCode=39]
[isActionKey=false]
[KEY_PRESSED,keyCode=222,keyText=Quote,keyChar=''',keyLocation=KEY_LOCATION_STANDARD,rawCode=222,primaryLevelUnicode=39,scancode=40,extendedKeyCode=0x27]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ixanos
Offline
Joined: 2008-12-06
Points: 0

of course. This is a work aorund and not a permanent fix! Whenever this bug is corrected a fresh install and a removal of the workaround will be done!

ixanos
Offline
Joined: 2008-12-06
Points: 0

I solved this issue by adding a KeyAdapter reacting at keyPressed with:

public void keyPressed(KeyEvent ke)
{
if ( ke.getKeyChar() == '\''
|| ke.getKeyChar() == '\"' )
{
ke.consume();
}
}

This way the characters are typed into the JTextPane without any obscure cursor movements.

cheers
ixanos

anthony_p
Offline
Joined: 2006-07-24
Points: 0

You do realize that the workaround will make your application behave incorrectly once the bug 6882912 gets fixed, right?

ixanos
Offline
Joined: 2008-12-06
Points: 0

... I mean : the cursor jumps ONE position instead of simply typing the character in the current position

anthony_p
Offline
Joined: 2006-07-24
Points: 0