Solved

TextArea, automatic scrolling?

Posted on 1997-09-15
3
1,156 Views
Last Modified: 2006-11-17
I have a TextArea in which I'm writing a lot of text (>=1000 rows). I'm writing the lines one by one with append (it is a log of what is happening in the program). Is there any way I can make the TextArea scroll while I'm writing, so that the last line is always seen?

Eva
0
Comment
Question by:evamf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
gerry99 earned 100 total points
ID: 1226954
I'd recommend using a List instead of a TextArea.

When you add an item call

list.select( list.size()-1 );

to select the last item in this list. This will scroll the list
so that the last line is selected. The downside, is that
List doesn't come with a horizontal scrollbar, so each item
should fit within the width of your control.

Hope this helps.
0
 

Author Comment

by:evamf
ID: 1226955
No, it does NOT scroll the list.

But the list does have a horizontal scrollbar. I'm using Java 1.0.2, maybe there's a difference between versions?

Any other suggestions?

Eva

0
 
LVL 1

Expert Comment

by:gerry99
ID: 1226956
I was a little imprecise in my answer, so I created a test
applet with Visual Cafe.  The list method to use is:
makeVisible( int index )

This applet creates a List, and then starts a thread which adds
2 lines a second to it.  The last line added is always visible.
The List scrolls when each line is added.  Tested in Appletviewer
under Windows95.

Here is my complete source.
/*
    A basic extension of the java.applet.Applet class
 */

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

public class Applet1 extends Applet implements Runnable
{

      public void init() {
            super.init();

            //{{INIT_CONTROLS
            setLayout(null);
            addNotify();
            resize(426,266);
            list1 = new java.awt.List(0,false);
            add(list1);
            list1.reshape(65,36,238,174);
            //}}
            
            // start a thread to do some stuff
            m_thread = new Thread( this );
            m_thread.start();
      
      }

      public boolean handleEvent(Event event) {
            return super.handleEvent(event);
      }
      
      public void run()
      {
          try
          {
              while ( true )
              {
                  list1.addItem( new String( "count " + iCount ) );
                  list1.makeVisible( list1.countItems() -1 );
                  iCount++;
                  m_thread.sleep( 500 );
              }
          }
          catch( Exception e )
          {
              System.out.println("exception" + e );
          }
      }

      //{{DECLARE_CONTROLS
      java.awt.List list1;
      //}}
      Thread m_thread;
      int iCount = 0;
}

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question