Aligning Textarea

Posted on 1997-08-21
Last Modified: 2012-05-04

OK, this is probably really simple for a seasoned Java coder, but, I have
an application that opens a textarea as a log window. However, whenever
the window fills, the window does not automatically scroll down. Is there
a way to this?

Question by:slyfoxx
  • 2
LVL 10

Expert Comment

ID: 1225514
try following example :
simply click on applet field to add row ro TextArea
This one scrolls in appletviewer in JDK1.02
I think you do not appended text but replaced all text setting
it with setText() method. That's why it doesn't scroll

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

        public class check extends Applet
        {int i=0;
         TextArea ta;
         public void init()
         {ta=new TextArea(10,10);
         public boolean mouseDown(Event e, int x, int y)
         { ta.appendText("\n"+i);
           return true;


Author Comment

ID: 1225515
Sorry, No good.

Irrespective of whether I append to the textarea or recreate all the text, the view of the text in the textarea is the same, the view does not scroll down automatically. (i.e. Functionally the same as the scroll bar being at the top and not moving.)

I am running jdk 1.1.3 on a solaris 2.5 machine under X.

Here is a copy of the code I am using.

import java.awt.*;

public class monitor {
  Frame fr = new Frame("Simulator Monitor");
  TextArea txt = new TextArea("", 12, 72);
  String text = "";

  monitor() {
    fr.setFont(new Font("Courier", Font.BOLD, 10));
    txt.append("Socket Connection Established\n");

 public void title(String t) {
    fr.setTitle("MR Simulator Monitor: "+t);

  public void add(String t) {
    text = text+t;

  public void add(int c, String t) {
    text = text+("("+c+") "+t);

  public void addln(String t) {
    text = text+t+"\n";

  public void addln(int c, String t) {
    text = text+"("+c+") "+t+"\n";

  public void addln() {
    text = text+"\n";

  public void update() {
    int end = text.length();
    txt.replaceRange(text, 0, end);


Accepted Solution

gerry99 earned 50 total points
ID: 1225516
I'd recommend using a List instead of a TextArea.

When you add an item call 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.

Author Comment

ID: 1225517
Interesting, I hadn't thought of it that way... Thanks...

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

Suggested Solutions

Title # Comments Views Activity
Systems talking to each other 5 124
Error with Java/Cache JDBC Classpath 2 30
stackato and cloud 4 68
fibonacci ten numbers 4 26
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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 …

912 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

17 Experts available now in Live!

Get 1:1 Help Now