Re: Newbie on JtextArea swing component
Hi All,
Thanks to everyone who has contributed to this thread. For
completeness, I now have a working solution but I'm still puzzled by
the behaviour of the JTextArea object. My code now looks like this:
try
{
FileInputStream fstream = new FileInputStream(SrcFile);
BufferedReader in = new BufferedReader(new
InputStreamReader(fstream));
String thisline;
while ( (thisline = in.readLine()) != null)
{
jT_SourceCode.append(thisline+"\n");
}
in.close();
jT_SourceCode.setSelectionStart(jT_SourceCode.getLineStartOffset(SrcLine-1));
jT_SourceCode.setSelectionEnd(jT_SourceCode.getLineEndOffset(SrcLine-1));
jT_SourceCode.setSelectedTextColor(java.awt.Color.red);
jT_SourceCode.setSelectionColor(java.awt.Color.yellow);
jT_SourceCode.requestFocus();
}//try
catch (Exception e)
{
System.err.println("File input error");
}//catch
jT_SourceCode ismy JTextArea object with default properties, except
tab size set to 4 and font set to Courier 12 plain.
The highlighted line rarely appears at the top of the viewport but it
is highlighted and I can see which one it is and that's all that
matters to me.
Nothing is changed on the display until the final call to
requestFocus(). Don't know why this is but it now works.
Thanks again,
Richard.