The Artima Developer Community
Sponsored Link

Java Answers Forum
Sending outputs to JTextArea

1 reply on 1 page. Most recent reply: Dec 5, 2004 5:58 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
karim

Posts: 5
Nickname: apahliani
Registered: Nov, 2004

Sending outputs to JTextArea Posted: Dec 4, 2004 3:49 PM
Reply to this message Reply
Advertisement
Hi,two questions
Since I am writting an application ,need a place to send the output there to check the result and also scroll.I was trying to use a JTextArea object (some methods likebut append and insert)but it did not work because it does not append the outputs vertically.I need something like println which can send the output to it but able to scroll (vertically) there.
Does anybody know about a free JAVA debugger?


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Sending outputs to JTextArea Posted: Dec 5, 2004 5:58 AM
Reply to this message Reply
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);
        }
    }

Flat View: This topic has 1 reply on 1 page
Topic: Checking the arrays then adding and averaging... Previous Topic   Next Topic Topic: Need file of words

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use