JDK-4765322 : JTextField/JTextArea - Can not enter correct ISO-8859-1 characters
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-10-18
  • Updated: 2002-10-31
  • Resolved: 2002-10-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Relates :  
Description

Name: sv35042			Date: 10/18/2002


FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000
[Version 5.00.2195] Sevice Pack 1 Build 2195


A DESCRIPTION OF THE PROBLEM :
Using a regular US Keyboard with an ALT Key and a
numeric pad, Extended ASCII characters can be entered
by holding down the ALT Key, pressing a valid sequence
of numbers from the numeric pad, and then releasing
the ALT Key.
 
For example: the value "����" can be generated by
ALT+0243.
 
I noticed that its possible to paste these types of
characters into a JTextField, but when you try to
use the keyboard, the wrong value is inputted.
 
When I try to enter "����" for example, I end up with
"����" instead.

In fact you can see this using sample code I found
to reproduce this:

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class KeyDemo extends JFrame implements KeyListener{
    private String line1 = "", line2 = "", line3 = "";
    private JTextArea textArea;
    
    public KeyDemo()
    {
        super( "Key Demo" );
        textArea = new JTextArea( 10, 15 );
        textArea.setText( "Press Key" );
        textArea.setEnabled(false);
        getContentPane().add(textArea);
        
        addKeyListener(this);
        
        setSize(350,100);
        setVisible(true);
    }
    
    public void keyPressed( KeyEvent event )
    {
        line1 = "Key pressed: " + event.getKeyText(
event.getKeyCode() );
        setLines2and3( event );
    }
    
    public void keyReleased( KeyEvent event )
    {
        line1 = "Key released: " + event.getKeyText(
event.getKeyCode() );
        setLines2and3( event );
    }
    
    public void keyTyped( KeyEvent event )
    {
        line1 = "Key typed: " + event.getKeyChar();
        setLines2and3( event );
    }
    
    
    private void setLines2and3( KeyEvent event )
    {
        line2 = "This key is " + (event.isActionKey
() ? "" : "not " ) +
        "an action key";
        
        String temp = event.getKeyModifiersText(
event.getModifiers() );
        
        line3 = "Modifier keys pressed: " +
        (temp.equals( "" ) ? "none" : temp );
        
        textArea.setText(line1 + "\n" + line2 +"\n" + line3
+ "\n");
    }
    
    public static void main( String args[] )
    {
        KeyDemo application = new KeyDemo();
        
        application.getDefaultCloseOperation();
    }
}

execute the program and type ALT+0243. You should see
���� but instead you see ���� instead
 
Refer to http://charlie.balch.org/asp/ascii.asp to test
other extended ascii characters.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Write a simple application/applet with a textfield box
or use the sample code I provided.
2. Launch the app and set focus on the text field via the
mouse.
3. Type ALT+0243 and examine the character in the
textfield/textarea.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected Results:  I should see ���� when I type ALT+0243. To
prove this is the expected results, launch a browser,
notepad, wordpad, or any other non-java application and
type that sequence of keystrokes. You'll always see ����.
 
Actual Results: I see ���� instead.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class KeyDemo extends JFrame implements KeyListener{
    private String line1 = "", line2 = "", line3 = "";
    private JTextArea textArea;
    
    public KeyDemo()
    {
        super( "Key Demo" );
        textArea = new JTextArea( 10, 15 );
        textArea.setText( "Press Key" );
        textArea.setEnabled(false);
        getContentPane().add(textArea);
        
        addKeyListener(this);
        
        setSize(350,100);
        setVisible(true);
    }
    
    public void keyPressed( KeyEvent event )
    {
        line1 = "Key pressed: " + event.getKeyText( event.getKeyCode() );
        setLines2and3( event );
    }
    
    public void keyReleased( KeyEvent event )
    {
        line1 = "Key released: " + event.getKeyText( event.getKeyCode() );
        setLines2and3( event );
    }
    
    public void keyTyped( KeyEvent event )
    {
        line1 = "Key typed: " + event.getKeyChar();
        setLines2and3( event );
    }
    
    
    private void setLines2and3( KeyEvent event )
    {
        line2 = "This key is " + (event.isActionKey() ? "" : "not " ) +
        "an action key";
        
        String temp = event.getKeyModifiersText( event.getModifiers() );
        
        line3 = "Modifier keys pressed: " +
        (temp.equals( "" ) ? "none" : temp );
        
        textArea.setText(line1 + "\n" + line2 +"\n" + line3 + "\n");
    }
    
    public static void main( String args[] )
    {
        KeyDemo application = new KeyDemo();
        
        application.getDefaultCloseOperation();
    }
}


---------- END SOURCE ----------
(Review ID: 159422) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis
14-06-2004

EVALUATION Name: ik75403 Date: 10/31/2002 JTextField and JTextArea typing whatever has been typed on the keyboard. The expected character has not been typed because text component had not received the expected keyEvent. Moving this bug to awt team ====================================================================== Sounds like a duplicate of 4623376. The character the submitter is describing didn't come through in the bug report. ###@###.### 2002-10-31 Using JDK1.4.1_01, Alt-0243 gives me the plus/minus character. Using JDK1.4.2 build 4, I get o-acute. I also get o-acute when using Wordpad, and it matches the entry in the table at the URL the submitter supplied, so I believe this bug is integrated in build 4 of 1.4.2. ###@###.### 2002-10-31
31-10-2002