Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4159610
Votes 65
Synopsis Menu accelerator gets inserted into text
Category java:classes_awt
Reported Against 1.2 , 1.1.6 , 1.2fcs , 1.2rc1 , 1.2beta4 , swing1.1
Release Fixed 1.2.2-002, 1.3(kestrel-beta) (Bug ID:2021913)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 4160723 , 4165650 , 4176985 , 4186905 , 4193779 , 4200559 , 4301105 , 6422318
Submit Date 22-JUL-1998
Description
If I add an acceleraor (like alt+n) to a menu entry, and if the current input
focus in a JTextArea, and if I type the alt+n key sequence then *both* the accelerator is activated and an "n" gets inserted into the text.  What appears to be happening is that when alt+n is typed both a KeyPressed and a KeyTyped
event get sent.  KeyPressed activates the menu action correctly.  The KeyTyped
event is supposed to be ignored by the TextArea, but it appears not to be.
The same thing happens with meta, but not with ctrl.
Work Around
Remove the focus from the TextArea before using a menu accelerator, 
or delete the unwanted character after using one.  

  xxxxx@xxxxx   1998-09-01
Evaluation
I can reproduce this with both JDK1.1.6 and 1.2 on Solaris, with the
current build.  I'm taking a look at it -- strange that there should
be a regression like this...

  xxxxx@xxxxx   1998-07-29


There are currently some problems with
KeyEvents at the native level that are
rather difficult to work around.  The
issue is with events of type KeyEvent.KEY_TYPED.

Background:
    
    Typically this event is used to enter
    text into an editable text component.
    Sometimes unicode characters desired 
    as "typed" characters can be composed
    of multiple key presses, for example
    a German PC-Type keyboard has no keys for 
    characters like [ ] { } \ @
    
      To type a '@' on a PC with such a keyboard running Windows, you type
      Alt-Gr + 'Q' , this produces the character '@'.  More Alt-Gr sequences
      exist for the other characters mentioned above, among others:
      
	    Alt-Gr + '7'  ==> '{'
	    Alt-Gr + '8'  ==> '['
	    Alt-Gr + '9'  ==> ']'
	    Alt-Gr + '0'  ==> '}'
	    Alt-Gr + '2'  ==> '²'
	    Alt-Gr + '3'  ==> '³'
	    Alt-Gr + '+'  ==> '~'
	    Alt-Gr + 'ß'  ==> '\'
	    ... etc ...
	    
	    Btw. the newest addition is
	    
	    Alt-Gr + 'e'  ==> the new euro currency sign
	    

The Problem:

    The events generated for KeyEvent.KEY_TYPED differ
    between windows and solaris, neither of which seem
    correct.  
    
    On windows, pressing some combinations of
    keys generates a typed event that has modifiers.  If
    one presses ALT + 'n' for example, a key typed event
    will be generated with a character of n and a modifier
    of ALT.  This event isn't really wanted at all since it's
    not a printable character and doesn't represent a unicode
    character.  If an Alt-Gr + 'q' is typed, the desired 
    key typed event is generated, with modifiers although
    it's not clear one wants the modifiers in this case.
    
    On solaris, pressing some combinations of keys
    generated a typed event as well, but never with modifiers.
    This is even worse than on the PC.  Pressing ALT + 'n'
    will produce a typed event with a character code of 'n'
    and no modifiers.  This appears as if the user typed an
    'n'.  When typing accellerators, this will cause text to
    be added to the text component that is not desired, and 
    there is no way to filter it out.

I'm transferring this bug to classes_awt as it's a problem 
with the native awt.

  xxxxx@xxxxx   1998-08-27


There are a number of bugs having to do with KEY_TYPED event problems.  
(See also 4024849, 4028470, 4069196, 4153069, 4114565, and 4100317.)
They need to be fixed, but it would probably be too risky to wade 
into this so close to code freeze.  Since this bug doesn't cause a 
hang or crash (or comparably severe problem), it probably doesn't meet 
the criteria for fixing at this late date, so I'm moving it to a P4.  
We'll move this to the top of the list right after fcs.  

  xxxxx@xxxxx   1998-09-01






This bug have different causes on Win32 and Solaris.

On Win32 the problems is that Swing receives InputMethodEvent's
instead of KEY_TYPED KeyEvent's.  This is reported under 4186905:
"JTextPane no longer dispatches keyTyped events to a KeyListener"
filed against classes_awt_im.

On Solaris the problem is missing ALT modifier on the KeyEvent.  See
4220772: "Key modifiers not passed for KEY_TYPED events on Solaris"

  xxxxx@xxxxx      1999-04-05

======================================================================

Fixed the Solaris version of this: 4193779

A test case for this bug (both Solaris and Windows) is at: 
jdk:/ws/jdk1.3/test/java/awt/swing/event/KeyEvent/MenuShortCut

  xxxxx@xxxxx   1999-04-08

The windows version of this has also been fixed.
  xxxxx@xxxxx   1999-08-06
Comments
  
  Include a link with my name & email   

Submitted On 23-JAN-1999
dcebula
I defined the accelerator sequence using registerKeyboardAction().  The invoked
action listener makes the text component un-editable and sets a Timer to change
the field back to editable.  The desired method is then called.  This sets up a
potential race condition, but I haven't encountered problems with it yet.


Submitted On 22-FEB-1999
alan griffiths
Note that there are similar problems with 
JTextField and Action buttons. (see 
<A href=4200559.html>4200559</A>
 - which is closed as a dup of this.)


Submitted On 25-FEB-1999
RickN
This makes setting mnemonics for the menus rather
destructive.  The problem that I have with making
the textfield uneditable is that this moves the
focus to another component (Possibly a text field).
I had better luck with putting a KeyListener on
the Jframe & doing a gratuitous "fileMenu.doClick()"
as soon as the VK_ALT key is pressed.  This gives
an almost normal look & feel.


Submitted On 12-MAY-1999
jmrozak
***This workaround is also posted in 
bugs 4186905 and 4200559***
When working with JDK 1.2.0 under Win95/NT I've
noticed this in JTextField as well, that Alt+x
inserts an 'x' into the field in addition to
processing the Alt+x combo.
I have a workaround for this, and have added it
to my 'SwingText' package of Open Java Source
components, found at:
http://www.enteract.com/~goose/java/swingtext
The workaround goes like this:
1)  Establish an object-wide flag like "altIsDown".
2)  in keyPressed(), if the Alt key is pressed,
    set (altIsDown = true).
3)  in processInputMethodEvent(), only if the 
    Alt key is NOT pressed, forward the event
    to its parent.  Then clear the flag:
    if(! altIsDown) super.processInputMethodEvent();
    altIsDown = false;
In my environment, at least, mnemonic key handling
still works OK when using this workaround.  
Care must be taken to re-enable the field
during Alt-Tab, dialog popups, etc.  Note
that putting the (altIsDown = false) in the
processInputMethodEvent() handler is easier than
trying to reset it in keyReleased(), focusGained(),
etc.  


Submitted On 30-MAY-1999
jgkarol
This one still seems to be around on Win32 platform with new JDK 1.2.2. Oddly
enough, the other night I tinkered with the separate Swing 1.1.1 beta 2 (I
think it was), which offered EXE compiled versions of the Swing demos. When I
ran the SwingSet compiled, it worked fine (in other words, menu accelerator
keypresses weren't echoed to the text boxes), and yet when I installed the new
JDK 1.2.2, it looks as though they are back again.
Looks like it may be time to go back to mnemonic-less menus again. :-)


Submitted On 15-JUN-1999
spestov
It says that it's fixed in a `non-public release'.
What does this mean? When will it appear in a
mainstream JDK version? It is a very major problem.


Submitted On 21-JUN-1999
MiguelM
This is still a problem in JDK 1.2.2RC


Submitted On 15-JUL-1999
larryhy
This is still a bug in JDK 1.2.2 and I agree with spestov in that it is a VERY
MAJOR problem. Do you realize that there are many people who "fly around
products" using the keyboard only? For those people, and for ANYONE who
uses the keyboard, this bug is UNACCEPTABLE.
Do you also realize that this bug causes user's filenames to be renamed? Yup.
If you fire up FileChooserSaveAs dialog box, enter "myfile" as the
name and then hit "Alt-s" for "Save" the file that gets
saved is "myfiles". This stinks should be fixed immediately!


Submitted On 09-SEP-1999
IFC
I have faced this problem with JTextArea. I am using JDK1.2.2. One workaround
is to trap Key pressed event and when alt key is a modifier for the KeyEvent
then focus can be shifted to any component other than JTextArea temporarily.
This bug should be fixed.


Submitted On 11-OCT-1999
pjknowles
I would like to vote for this bug to be fixed, but I cannot, because the system
says that
it is fixed. As it is quite clearly not fixed in the JDK1.2.2 release, how
about setting the
status of this bug to open again to allow the various people to whom it is
causing
problems to cast their vote appropriately.



Submitted On 11-OCT-1999
pjknowles
Having included the above comment requesting the re-opening of this
bug, I thought I should include my reason for refuting Sun's claim that this
is a problem with the native awt
Sun JDK1.8.8 with Swing-1.1.1 - works OK
IBM JDK1.8.8 with Swing-1.1.1 - works OK
MSVM Version 5.00.3182 with Swing-1.1.1  - works OK
Sun JDK1.2.2 with built-in Swing (Whatever version that is!) - fails
Sun JDK1.2.2 with Swing-1.1.1 set thru -Xbootclasspath - works OK
So unless Sun have managed to break the AWT in JDK1.2.2 the problem appears
to be with the Swing implementation shipped in the 1.2.2 package, hence my
request to re-open this bug for votes


Submitted On 21-FEB-2001
garybiagioni
<BR>


Submitted On 21-FEB-2001
garybiagioni
In response to jmrozak

Thanks for placing your workaround on the web for the ALT-? 
keys getting put into the JTextField.  It saved me a fair 
bit of time.  Here is another way to do it without a 
listener.  The processKeyEvent() is called before
processInputMethodEvent().  You may have one small bug in 
your code.  Try pressing ALT-&lt;CR&gt; (or some other inoculous 
ALT key combination) The next key stroke may be ignored 
because the ignore flag is set.  What I do is wipe out
the flag a the start of the processing of any key.  This 
would mean resetting the ignore flag in your keyPressed() 
and keyTyped() methods.


Thanks again.

My patch follows:

   //	If the Alt+key combo is pressed then don't display 
the keystroke.
    // this is works around a JDK 1.2 bug.

  private boolean ignoreKey;
  protected void processKeyEvent(KeyEvent e) {
      ignoreKey = false;
      super.processKeyEvent(e);
      if( e.isAltDown() &amp;&amp;
          e.getKeyCode() != KeyEvent.VK_ALT &amp;&amp;  



PLEASE NOTE: JDK6 is formerly known as Project Mustang