Solved

TextArea, automatic scrolling?

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse java  build path 6 56
expectj telnet failing 5 35
spring jars download 1 26
maven module vs maven project 3 21
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)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

813 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

10 Experts available now in Live!

Get 1:1 Help Now