Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Advanced-java] TextArea, large file and setCaretPosition(0)


  • From: jorti@xxxxxxxxx (Jose Ortiz)
  • Subject: [Advanced-java] TextArea, large file and setCaretPosition(0)
  • Date: Fri, 22 Feb 2002 16:58:21 -0500

Try placing the JTextArea inside a JScrollPane,

	JScrollPane scroller.setViewportView( jtextarea );

then, get the Viewport,

	JViewport viewport = scroller.getViewport();

and do
	viewport.setViewPosition( new Point(0,0) );

you may need to do this constantly in a loop while the loading is not
finished.
 
An alternative is to inspect the source code of JTextArea and see what
append(String) or setText(String) are doing (obviously, they are placing
the caret at the end after appending more text). The idea is to subclass
JTextArea and overwrite say the append method taking care of removing
the caret placement whenever you set a flag. 

	class myJTextArea extends JTextArea {
	public void append(String s ) {
	   if( !flagSet ) {
		super.append(s);
	   	return;
	  }
	  // here place the code from super class without
	  // the caret placement.
	}

flagSet should be true for the loading job. It should be false for
normal behaviour.

Jose

ribchr00@xxxxxxxxxxxxxx wrote:
> 
> Hi,
> 
> To avoid the waiting for a large file to be loaded in a
> TextArea, when a certain number of lines is read, I send
> them to the TextArea. I would like the process running
> out in the background. The user should not notice
> anything. My problem is that the caret position always
> changes to the end when text is appended. I tried some
> ideas like a loop or a thread setting the caret position
> to 0 but it did not work. Has anybody a better idea? For
> any suggestion I would be glad. Cheers,
> 
> richard
> _______________________________________________
> Advanced-java mailing list
> Advanced-java@xxxxxxxxxxxxxxxxxxxxxx
> http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java

-- 
-------------------------------------------------------------------
                                      Jose L. Ortiz, Ph.D.
                                      Senior Development Engineer
     _/_/    _/_/  _/_/_/_/    _/     
    _/ _/  _/ _/  _/      _/  _/      Mechanical Dynamics, Inc. 
   _/  _/_/  _/  _/      _/  _/       2300 Traverwood Drive
  _/   _/   _/  _/      _/  _/        Ann Arbor, MI 48105, USA
 _/        _/  _/_/_/_/    _/         phone : (734) 887-2551
                                      e-mail: jorti@xxxxxxxxx
 The virtual prototyping company      web   : http://www.adams.com
-------------------------------------------------------------------