Solved

TextArea, automatic scrolling?

Posted on 1997-09-15
3
1,151 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now