Results 1 to 3 of 3
  1. #1
    kosmos890 is offline Member
    Join Date
    Apr 2012
    Posts
    40
    Rep Power
    0

    Default How can I simulate a JTextArea as a text console output?

    Sorry for my bad English.

    I want to show a large text (more than 6000 lines).
    I used setText(String str) and setDocument(Doument doc) methods .
    I call these methods from a SwingWorker or SwingUtilities.invokeLater but GUI is frozen.

    I'm looking for a way to show the text gradually so the GUI is responsive and the user can stop the process.
    Thanks in advance.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: How can I simulate a JTextArea as a text console output?

    setText ? How do you generate the (600 lines) string?
    Why you don`t use the append method from the JTextArea?

  3. #3
    kosmos890 is offline Member
    Join Date
    Apr 2012
    Posts
    40
    Rep Power
    0

    Default Re: How can I simulate a JTextArea as a text console output?

    @eRaaaa
    Thanks for your reply.
    I want to make a Web Extractor with Jsoup Library.
    I parse a Html document from the web and then I use select(String jquery) method.
    Java Code:
    import java.io.IOException;
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.nodes.Element;
    import org.jsoup.select.Elements;
    import org.openide.util.Exceptions;
    
    public class JSoupDemo {
    
        public static void main(String[] args) {
    
            Document doc = null;
            String url = "http://www.java-forums.org/awt-swing/68936-how-can-i-simulate-jtextarea-text-console-output.html";
            int counter = 0;
            StringBuilder sb = new StringBuilder();
            String result;
    
            try {
                doc = Jsoup.connect(url).get();
    
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
    
            //This is the worst case
            Elements elements = doc.select("*");
    
            //A usefull jquery 
            // elements=doc.select("a");
            // Matched elements may include this element, or any of its children
            System.out.println(elements.size()); // 879 Elements
    
            for (Element elem : elements) {
                sb.append("\n\n(").append(++(counter)).append(")");
                sb.append("\n").append(elem.toString());
            }
    
            result = sb.toString();
            System.out.println(result);
        }
    }
    The code above is a console demo of how I have so many lines.
    For my GUI I use Document and JEditorPane.
    To improve performance of big texts showing in JEditorPane I also read :
    JavaTechniques Faster JTextPane Text Insertion (Part I)
    Slow JEditorPane/JTextPane and performance improvements.

Similar Threads

  1. Console like Environment in JTextArea
    By Kyle227 in forum AWT / Swing
    Replies: 4
    Last Post: 02-25-2011, 07:26 PM
  2. Need help with printing console output to JTextArea
    By ShinTec in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2010, 10:10 AM
  3. output to terminal instead of console on mac
    By firen in forum Advanced Java
    Replies: 0
    Last Post: 06-01-2010, 12:42 PM
  4. How Do You?? Get the Console Output as a GUI??
    By Lyricid in forum AWT / Swing
    Replies: 10
    Last Post: 11-20-2009, 11:35 PM
  5. How to align the output on console?
    By sfe23 in forum New To Java
    Replies: 5
    Last Post: 03-30-2009, 03:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •