JDK-4028532 : Disable TextArea automatically scrolling on appending of text
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1997-01-28
  • Updated: 2000-01-20
  • Resolved: 2000-01-20
Description

Name: mc57594			Date: 01/28/97


Since JDK 1.0.2, the TextArea scrolls to the end to show
the appended text when TextArea.appendText() is invoked.  This is not
always the desired behavior.  One example is if a long file is being
read in, the user may like to view the file and stay on the first page
while the remainder of the file is being read in.  Please add an option
to disable automatic scrolling on append.

The following applet indicates the problem.  Save it in
TestTextArea.java
then Compile it and run it with "appletviewer TestTextArea.java".  While
new lines are added to the end, the text area scrolls down to show the
last lines added.  I would like to be able to show the first screenful
while more lines are being appended to the end.

/*
  <title>TextArea Tester</title>

  <applet code="TestTextArea" width=600 height=400>
  </applet>
 */

import java.applet.*;
import java.awt.*;
import java.util.*;

public class TestTextArea extends Applet {
    TextArea     text_area;
    TextAppender appender;

    public void init() {
	text_area = new TextArea();
	appender = new TextAppender(text_area);

	setLayout(new BorderLayout());

	add("Center", text_area);
    }
}

class TextAppender extends Thread {
    TextArea text_area;

    TextAppender(TextArea text_area) {
	this.text_area = text_area;
	start();
    }

    public void run() {
	for (int i = 0; i < 100; i++) {
	    for (int j = 0; j < 10; j++) {
		text_area.appendText("line " + (i * 10 + j) + "\n");
	    }
	    try {
		sleep(1000);
	    } catch (Exception e) {
		System.out.println(e);
	    }
	}
    }
}
======================================================================

Comments
WORK AROUND Name: mc57594 Date: 01/28/97 None, short of writing my own text area, Ugh! ====================================================================== ###@###.### There is a work around that does not require writing your own text area. Whether it is intentional or not is the question I am wondering. Anyway, before making your textarea visible, append some text into the area. For some reason doing this disables the scroll bars and the scroll bar will stay at the top instead of the bottom on subsequent appends.
11-06-2004

EVALUATION close as will not fix. xianfa.deng@Eng 2000-01-19
19-01-2000