JDK-4909137 : Robot key action shift+left/shift+right does not select text in JTextField
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-08-19
  • Updated: 2003-09-08
  • Resolved: 2003-09-08
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 08/19/2003


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

java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
I've created a mouse and key event recoreder and player, when I found that the following scenario does not work:

Having the awt.robot selecting text in a text field with shift+[any motion key] does not work.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a JTextField with "This is a test" in it.
Use the awt.Robot to got to the end, then:
- press shift
- press and release left
- press and release left
- press and release left
- press and release left
- release shift


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the word "test" to be selected.
ACTUAL -
The cursor had moved, but there was no selection.

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class QuickTest extends JFrame
{
    public QuickTest()
    {
        this.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent event)
            {
                System.exit(0);
            }
        });

        JPanel bg = new JPanel();
        this.setContentPane(bg);

        JTextField textField = new JTextField("This is a test");
        bg.add(textField);
        
        this.setTitle("QuiclTest");
        this.pack();
        this.setVisible(true);

        //textField.requestDefaultFocus();

        Robot robot = null;
        try
        {
            robot = new Robot();
        }
        catch (AWTException e)
        {
            e.printStackTrace();
        }
        
        robot.keyPress(KeyEvent.VK_END);
        robot.keyRelease(KeyEvent.VK_END);
        
        robot.keyPress(KeyEvent.VK_SHIFT);
        
            robot.keyPress(KeyEvent.VK_LEFT);
            robot.keyRelease(KeyEvent.VK_LEFT);
            
            robot.keyPress(KeyEvent.VK_LEFT);
            robot.keyRelease(KeyEvent.VK_LEFT);
            
            robot.keyPress(KeyEvent.VK_LEFT);
            robot.keyRelease(KeyEvent.VK_LEFT);
            
            robot.keyPress(KeyEvent.VK_LEFT);
            robot.keyRelease(KeyEvent.VK_LEFT);
        
        robot.keyRelease(KeyEvent.VK_SHIFT);
    }
    
    public static void main(String[] args)
    {
        new QuickTest();
    }
}

---------- END SOURCE ----------
(Incident Review ID: 199216) 
======================================================================

Comments
WORK AROUND Disabling NumLock avoids the problem. ###@###.### 2003-09-08
08-09-2003

EVALUATION Probably related to 4908075. ###@###.### 2003-08-19 This is a duplicate of 4908075, and the same workaround applies. ###@###.### 2003-09-08
19-08-2003