Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TextArea, automatic scrolling?

Posted on 1997-09-15
3
Medium Priority
?
1,160 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 400 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses

609 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