🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #11110

JScrollPane + JTextArea

#11110
From: Ray Cheung
Date: Thu, 08 Jul 1999 00:00
93 lines
2872 bytes
This is a multi-part message in MIME format.
--------------C3288A4CB8B5FCCDD65FDC5C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I have a problem with the newer Swing versions that uses a JTextArea
inside a JScrollPane.

In older version of Swing (eg. swing-1.0.2), when you append text to the
TextArea, the ScrollPane scrolls to the latest text. In the new Swing
versions (eg. swing-1.1.1-beta1) no scrolling occurs and the oldest text
remain on screen. The is very annoying because I using the TextArea as a
logging screen. Is there some way of setting up the ScrollPane to
display the newest text? (Attached is a small test program that
illustrates the problem.)


Many thanks.

Ray

--

Ray Cheung

E-mail	cheungr@ecid.cig.mot.com or
	r.l.cheung@ieee.org
--------------C3288A4CB8B5FCCDD65FDC5C
Content-Type: text/plain; charset=us-ascii; name="TestScrollPane.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="TestScrollPane.java"

// File: TestScrollPane.java
// Author: Ray Cheung
// Problem:
//	When using jdk1.2 or swing-1.1.1-beta1 the scroll pane always
//	display the oldest text instead of scrolling to the newest
//	text as text is appended to the textArea. (This does not
//	happen in older versions of Swing, eg. swing-1.0.2.




// import com.sun.java.swing.*;	// for swing-1.0.2
import javax.swing.*;	// for jdk1.2 or swing-1.1.1-beta1
import java.awt.*;
import java.io.*;

public class TestScrollPane
{
	public static void main ( String args[] )
	{
		JFrame frame;

		frame = new JFrame( "Test Scroll Pane" );

		Container cp = frame.getContentPane();
		cp.setLayout( new GridBagLayout() );

		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 0;
		c.gridwidth = c.REMAINDER;
		c.gridheight = c.REMAINDER;
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 1.0;
		c.weighty = 1.0;
		c.anchor = GridBagConstraints.NORTHWEST;
		
		JTextArea textArea = new JTextArea();
		textArea.setFont( new Font( "Courier", Font.PLAIN, 12 ) );
		JScrollPane sp = new JScrollPane( textArea );
		cp.add( sp, c );

		frame.setSize( 400, 500 );
		frame.setVisible( true );

		for ( int i = 0 ; i < 100 ; i++ )
		{
			textArea.append( "Line " + i + "\n" );
		}
	}
}







															

--------------C3288A4CB8B5FCCDD65FDC5C--
Technical Details
Message-ID: <3784578B.A66FBC62@ecid.cig.mot.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,4004693220d07f0d,start
X-Google-Attributes: gid111d45,public
From: Ray Cheung <cheungr@ecid.cig.mot.com>
Subject: JScrollPane + JTextArea
Date: 1999/07/08
Message-ID: <3784578B.A66FBC62@ecid.cig.mot.com>
X-Deja-AN: 498478058
Organization: Motorola
Content-Type: multipart/mixed; boundary="------------C3288A4CB8B5FCCDD65FDC5C"
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing