Re: Newbie on JtextArea swing component
On 31 Jul, 21:20, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
I want to be able to set an arbitrary line as the top
visible line in the GUI and have the line highlighted.
seehttp://mindprod.com/jgloss/jscrollpane.html
andhttp://mindprod.com/jgloss/jtextarea.html
There is a gotcha. Strangely you need SwingUtilities.invokeLater even
when you have only one thread.
--
Roedy Green Canadian Mind Products
The Java Glossaryhttp://mindprod.com
Thanks for the info. I took a look and it made some sense to me (so I
must be learning something :-) )
I found a workaround which doesn't quite do what I expected: My code
looks like this:
try
{
FileInputStream fstream = new FileInputStream(SrcFile);
BufferedReader in = new BufferedReader(new
InputStreamReader(fstream));
String thisline;
sline = 1;
schar = 0;
while ( (thisline = in.readLine()) != null)
{
jT_SourceCode.append(thisline+"\n");
schar += (thisline.length()+1); //don't forget CR that has
been added
if(sline == SrcLine)
{
System.out.println("Found source line "+SrcLine+" "+sline
+" "+schar);
System.out.println("Lines -
"+jT_SourceCode.getLineCount());
System.out.println("Char offset -
"+jT_SourceCode.getLineStartOffset(sline));
jT_SourceCode.setCaretPosition(jT_SourceCode.getLineStartOffset(sline));
}//if found source line
sline++;
}
in.close();
}//try
The numbers that are printed out by the System.out.println()'s are
correct (I counted the lines and characters in a separate text editor)
but the text in the JTextArea is not placed at the correct place. Does
the JTextArea convert tabs to spaces? How does it handle newlines/
Carriage returns?
TIA,
Richard.