Solved

TextArea, automatic scrolling?

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now