[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: Getting scroll pane to display bottom of text (using Swing)

Peter Toye wrote:
I'm trying to get JTextArea in a JSCrollPane to display the latest text after I use append. Whatever I do it seems to scroll up to the top of the area, which isn't very useful. Thanks in advance for any help.

The code I've got (very much cut down of course is:

	JTextArea textArea = new JTextArea();
	JScrollPane scrollPane = new JScrollPane(textArea);
	.
	.
	.
	textArea.append("various bits of data\n");
	scrollPane.scrollRectToVisible(new Rectangle(0,textArea.getHeight
()-scrollPane.getHeight(),
	  scrollPane.getWidth(),scrollPane.getHeight()));
		
	scrollPane.validate();
	
Peter

Hope this can help you : http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html -- JACK YAO, Beijing, China