JDK-5003402 : REGRESSION: java.awt.TextArea stops scrolling when it loses the keyboard focus.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-02-25
  • Updated: 2005-03-03
  • Resolved: 2004-10-25
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 JDK 6
5.0u2Fixed 6 b10Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Name: gm110360			Date: 02/25/2004


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


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600] and Microsoft Windows 2000 [Version 5.00.2195]


EXTRA RELEVANT SYSTEM CONFIGURATION :
Use this HTML file for the applet below:

<?xml version="1.0" encoding="us-ascii"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test Applet</title>
</head>
<body>
<h1>Test Applet</h1>
<p>This is a test applet.</p>
<p><applet code="TestApplet.class" width="300" height="100"></applet></p>
</body>
</html>


A DESCRIPTION OF THE PROBLEM :
When appending to a java.awt.TextArea, the vertical scroll bar automatically scrolls to see the last line appended when there is more text in the text area than will fit in the current size, regardless of which component has the focus. This works in Java version 1.0.2 through version 1.4.2_03.

In Java 1.5.0 Beta 1, the automatic scrolling occurs only when the text area has the keyboard focus. That's a problem for things like chat clients which need the incoming messages to scroll in the text area while the outgoing message text field has the keyboard focus.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the applet included below with the Java 1.5.0 Beta 1 appletviewer program.  Watch the automatic scrolling. Then click the text field at the bottom of the applet to give it the keyboard focus. Watch the automatic scrolling stop.

In Java version 1.4.2_03 and earlier, the automatic scrolling continues even when the text area loses the keyboard focus.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The scrolling should continue even when the text area loses keyboard focus.

ACTUAL -
The scrolling stops when the text area loses keyboard focus.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
None.


REPRODUCIBILITY :
This bug can be reproduced always.

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

public class TestApplet extends Applet implements Runnable {
    TextArea area;
    TextField field;
    Thread thread;

    public void init() {
        System.out.println("Initializing applet ...");
        area = new TextArea();
        field = new TextField();
        setLayout(new BorderLayout());
        add("Center", area);
        add("South", field);
        thread = new Thread(this);
    }

    public void start() {
        System.out.println("Starting applet ...");
        thread.start();
    }

    public void run() {
        try {
            for (int i = 0; i < 100; i++) {
                area.append("This is line number " + i + "\n");
                Thread.sleep(500);
            }
        }
        catch (InterruptedException e) {
            System.err.println(e);
        }
    }

    public void stop() {
        System.out.println("Stopping applet ...");
        thread.interrupt();
        area.setText("");
    }

    public void destroy() {
        System.out.println("Destroying applet ...");
        area = null;
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None.

Release Regression From : 1.4.2_03
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

Release Regression From : tiger-beta2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.
(Incident Review ID: 240335) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang FIXED IN: mustang
2004-09-17

SUGGESTED FIX ------- awt_TextArea.cpp ------- *** /tmp/sccs.vpaqT4 Tue Sep 14 14:29:00 2004 --- awt_TextArea.cpp Mon Sep 13 15:00:06 2004 *************** *** 176,182 **** --- 176,187 ---- } void AwtTextArea::EditSetSel(CHARRANGE &cr) { + // Fix for 5003402: added restoring/hiding selection to enable automatic scrolling + LockWindowUpdate(GetHWnd()); + SendMessage(EM_HIDESELECTION, FALSE, TRUE); SendMessage(EM_EXSETSEL, 0, reinterpret_cast<LPARAM>(&cr)); + SendMessage(EM_HIDESELECTION, TRUE, TRUE); + LockWindowUpdate(NULL); } void AwtTextArea::EditGetSel(CHARRANGE &cr) { *************** *** 907,913 **** CHARRANGE cr; cr.cpMin = getWin32SelPos(start); cr.cpMax = getWin32SelPos(end); ! SendMessage(EM_EXSETSEL, 0, (LPARAM)&cr); } /************************************************************************ --- 912,918 ---- CHARRANGE cr; cr.cpMin = getWin32SelPos(start); cr.cpMax = getWin32SelPos(end); ! EditSetSel(cr); } /************************************************************************ *************** *** 1001,1008 **** --- 1006,1018 ---- buffer[length-1] = '\0'; c->CheckLineSeparator(buffer); c->RemoveCR(buffer); + // Fix for 5003402: added restoring/hiding selection to enable automatic scrolling + LockWindowUpdate(c->GetHWnd()); + c->SendMessage(EM_HIDESELECTION, FALSE, TRUE); c->SendMessageW(EM_SETSEL, start, end); c->SendMessageW(EM_REPLACESEL, FALSE, (LPARAM)buffer); + c->SendMessage(EM_HIDESELECTION, TRUE, TRUE); + LockWindowUpdate(NULL); delete[] buffer; CATCH_BAD_ALLOC; void AwtTextArea::EditSetSel(CHARRANGE &cr) { + // Fix for 5003402: added restoring/hiding selection to enable automatic scrolling + LockWindowUpdate(c->GetHWnd()); + c->SendMessage(EM_HIDESELECTION, FALSE, TRUE); SendMessage(EM_EXSETSEL, 0, reinterpret_cast<LPARAM>(&cr)); + c->SendMessage(EM_HIDESELECTION, TRUE, TRUE); + LockWindowUpdate(NULL); } void AwtTextArea::EditGetSel(CHARRANGE &cr) { SendMessage(EM_EXGETSEL, 0, reinterpret_cast<LPARAM>(&cr)); } *** 905,915 **** void AwtTextArea::SetSelRange(LONG start, LONG end) { CHARRANGE cr; cr.cpMin = getWin32SelPos(start); cr.cpMax = getWin32SelPos(end); ! SendMessage(EM_EXSETSEL, 0, (LPARAM)&cr); } /************************************************************************ * TextArea native methods */ --- 910,920 ---- void AwtTextArea::SetSelRange(LONG start, LONG end) { CHARRANGE cr; cr.cpMin = getWin32SelPos(start); cr.cpMax = getWin32SelPos(end); ! EditSetSel(cr); } /************************************************************************ * TextArea native methods */ *** 999,1010 **** --- 1004,1020 ---- WCHAR *buffer = new WCHAR[length]; env->GetStringRegion(text, 0, length-1, buffer); buffer[length-1] = '\0'; c->CheckLineSeparator(buffer); c->RemoveCR(buffer); + // Fix for 5003402: added restoring/hiding selection to enable automatic scrolling + LockWindowUpdate(c->GetHWnd()); + c->SendMessage(EM_HIDESELECTION, FALSE, TRUE); c->SendMessageW(EM_SETSEL, start, end); c->SendMessageW(EM_REPLACESEL, FALSE, (LPARAM)buffer); + c->SendMessage(EM_HIDESELECTION, TRUE, TRUE); + LockWindowUpdate(NULL); delete[] buffer; CATCH_BAD_ALLOC; } ###@###.### 2004-09-14
2004-09-14

EVALUATION It is reproducible in 1.5.0. However, it is AWT bug intead of plugin. Tested on standalone application, it is still reproducible. public static void main(String[] args) { JFrame f = new JFrame("Test Applet Application"); TestApplet t = new TestApplet(); f.setContentPane(t); f.setSize(300, 100); f.setVisible(true); t.init(); t.start(); } Re-assign to awt. ###@###.### 2004-02-27 This bug is a result of removing the ES_NOHIDESEL style in the edit control (see 4095946). In the edit control which does not have this style, the selection is hidden when the focus is lost. When the selection is hidden, the control does not scroll automatically when sending EM_SETSEL/EM_REPLACESEL. ###@###.### 2004-09-08
2004-09-08