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); } } } } ======================================================================
|