|
|
Re: Sending outputs to JTextArea
|
Posted: Dec 5, 2004 5:58 AM
|
|
First of all, I would use a interface wich provides the methods you need, so you can have more possibilities to implemen it:
public interface LogStation {
public void appendLog (String s);
public void clearLog ();
}
Now to your problem: I created a form with a JScrollPanel (jScr_Log) containing a JTextArea (jTxA_Log). Here's the append code:
public void appendLog (String s) {
jTxA_Log.append(s + '\n'); //you could use a timestamp here
if (this.isVisible()) {
int mv = jTxA_Log.getScrollableUnitIncrement(jScr_Log.getBounds(), javax.swing.SwingConstants.VERTICAL, 1);
final int mh = 0;
java.awt.Point point = jScr_Log.getViewport().getViewPosition ();
point.y += mv;
jScr_Log.getViewport().setViewPosition(point);
}
}
|
|