Page 6 of 6 FirstFirst ... 456
Results 101 to 115 of 115
Like Tree3Likes

Thread: How display streamresults in JTextArea (Jlabel)

  1. #101
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    7

    Default Re: How display streamresults in JTextArea (Jlabel)

    In the end, the forum thread appeared also about XMLStreamwriter to Textarea transfer. So I have such question, the one that remains, after GUI creation, also due the fail of using Pipe in Out(in)Stream. If I want use pipe with PipedWriter (it seems works just with the characters/text). If I put such thing: XMLStreamWriter(StringWriter sw).
    How should I connect it with PipedWriter out out( sw ) or backward or should I use just write (read) method.
    Then I use PipedReader in(out). Then If I want to render in StringReader/BufferedReader sr, should I put in this kind –sr(in)?

  2. #102
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    7

    Default Re: How display streamresults in JTextArea (Jlabel)

    I cannot add the question to this one:http://www.java-forums.org/java-io/9...pedreader.html

  3. #103
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    28

    Default Re: How display streamresults in JTextArea (Jlabel)

    Why do you want to add a question to an old thread?
    You've been asked to create your own threads.
    If you think there's something useful in an old thread you can always provide a link to it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #104
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    7

    Default Re: How display streamresults in JTextArea (Jlabel)

    I cannot add the question to http://www.java-forums.org/java-io/9...pedreader.html.
    I can ask in the context of these thread - how to use Pipedwriter to transfer from streamresult to TextArea.read().
    F.e. StringWriter sw=...;
    Streamresult(sw);
    <...>
    StringReader sr=...;
    Textarea textarea.read(sw,null) --what manipulation should I do in <...>?

  5. #105
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    7

    Default Re: How display streamresults in JTextArea (Jlabel)

    Can I simply do such thing:
    PipedWriter out = sw || PipedWriter out(sw) || sw(out);
    StringReader sr =PipedReader in;
    PipedReader in(out);

  6. #106
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,012
    Rep Power
    35

    Default Re: How display streamresults in JTextArea (Jlabel)

    Can I simply do such thing:
    Try it and see what happens. If you have problems, post the code (a full program that can be compiled and executed for testing) and explain your problems.
    If you don't understand my response, don't ignore it, ask a question.

  7. #107
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    7

    Default Re: How display streamresults in JTextArea (Jlabel)

    I have surfed the internet and did not found such simple variant. I would not post a code as I already finished my work on GUI, but I would like to know if it is possible to make direct pipe between Writer and Rader, as pipe from Outputstream to Inputstream did not worked in practice. So maybe I did not connected corretly it.

  8. #108
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,012
    Rep Power
    35

    Default Re: How display streamresults in JTextArea (Jlabel)

    It is hard to test without code.
    If you don't understand my response, don't ignore it, ask a question.

  9. #109
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    29

    Default Re: How display streamresults in JTextArea (Jlabel)

    Quote Originally Posted by ark View Post
    Can I simply do such thing:
    PipedWriter out = sw || PipedWriter out(sw) || sw(out);
    StringReader sr =PipedReader in;
    PipedReader in(out);
    What is that supposed to mean? Is it just your wishful thinking; an idea you got without reading any documentation? It is complete nonsense.

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  10. #110
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    10

    Default Re: How display streamresults in JTextArea (Jlabel)

    I tried to create what OP is after, just to see if it's really that hard. So, I have cooked up something that I think the OP would like to see (interesting 20 minutes I must say :)). Does anybody have any objections if I dump a working concept in here? Or is it too much homework-ish that I shouldn't?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  11. #111
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    29

    Default Re: How display streamresults in JTextArea (Jlabel)

    Quote Originally Posted by SurfMan View Post
    I tried to create what OP is after, just to see if it's really that hard. So, I have cooked up something that I think the OP would like to see (interesting 20 minutes I must say :)). Does anybody have any objections if I dump a working concept in here? Or is it too much homework-ish that I shouldn't?
    I personally say, go for it, because this thread is so tiresome; the OP shouldn't try to tackle the problem(s) he's struggling with without having read any documentation at all.

    kind regards,

    Jos
    Norm and gimbal2 like this.
    Build a wall around Donald Trump; I'll pay for it.

  12. #112
    ark
    ark is offline Senior Member
    Join Date
    Apr 2015
    Posts
    288
    Rep Power
    7

    Default Re: How display streamresults in JTextArea (Jlabel)

    So easy question - I just need the example - the pattern no more

  13. #113
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    29

    Default Re: How display streamresults in JTextArea (Jlabel)

    Quote Originally Posted by ark View Post
    So easy question - I just need the example - the pattern no more
    So easy question? Well, maybe it was an easy question to start with, but you created a complete mess out of it; this thread is about all the problems in the world and you keep on adding to it instead of reading some elementary documentation before you start banging your keyboard and make invalid assumptions. The way you are trying to program is preposterous and I pity your future coworkers.

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  14. #114
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    10

    Default Re: How display streamresults in JTextArea (Jlabel)

    Well, here it goes.

    This demo class shows two threads using PipedOutputStream/PipedInputStream. One thread reads the Document and transforms it using an empty XSLT Transformer (so you get the basic XML) and pushes it to the PipedOutputStream. That in its turn is connected to the other end of a PipedInputStream that the other thread is using to feed it to the JTextArea.

    To OP/ark: I am not going to answer questions about this. You can study this yourself (JavaDoc FTW!!). As you know, public classes need to be in a file with the same classname. So put this in a file called Demo.java. The demo requires a test.xml in the same directory as you put this class in. Also, I've left the package name in there, which you probably want to change to where ever you are going to drop this file.

    Discalimer: I have made no attempt in handling any exception other than doing a printStackTrace(). All I know is that it works. Your mileage may vary.

    This is the output:



    Java Code:
    package forums.pipes;
    
    import org.w3c.dom.Document;
    import org.xml.sax.SAXException;
    
    import javax.swing.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.io.*;
    
    public class Demo {
        private JFrame frame;
        private JTextArea area;
    
        public static void main(String[] args) {
            new Demo();
        }
    
        public Demo() {
            frame = new JFrame();
    
            area = new JTextArea();
            JPanel buttons = new JPanel(new FlowLayout());
    
            buttons.add(new JButton(getTransformAction()));
            buttons.add(new JButton(getQuitAction()));
    
            frame.getContentPane().setLayout(new BorderLayout());
            frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
            frame.getContentPane().add(buttons, BorderLayout.SOUTH);
    
            frame.setSize(new Dimension(800, 600));
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    frame.setVisible(true);
                }
            });
    
        }
    
        private Action getQuitAction() {
            return new AbstractAction("Quit") {
                @Override
                public void actionPerformed(ActionEvent e) {
                    frame.dispose();
                }
            };
        }
    
        private Action getTransformAction() {
            return new AbstractAction("Transform") {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        transform();
                    }
                    catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };
        }
    
        private void transform() throws ParserConfigurationException, IOException, SAXException, TransformerException {
            PipedOutputStream pout = new PipedOutputStream();
            PipedInputStream pin = new PipedInputStream(pout);
    
            OutputRunner output = new OutputRunner(pout);
            InputRunner input = new InputRunner(pin);
    
            //I've named the Threads so I can check if they are properly gone in the debugger
            new Thread(output, "OutputThread").start();
            new Thread(input, "InputThread").start();
        }
    
    
        class OutputRunner implements Runnable {
            private OutputStream out;
    
            public OutputRunner(OutputStream out) {
                this.out = out;
            }
    
            @Override
            public void run() {
                try {
                    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(getClass().getResourceAsStream("test.xml"));
                    Source source = new DOMSource(document);
                    Result result = new StreamResult(out);
                    Transformer transformer = TransformerFactory.newInstance().newTransformer();
                    transformer.transform(source, result);
    
                    out.flush();
                    out.close();
                }
                catch (IOException | SAXException | ParserConfigurationException| TransformerException e) {
                    e.printStackTrace();
                }
    
            }
    
        }
    
        class InputRunner implements Runnable {
            private InputStream in;
    
            public InputRunner(InputStream in) {
                this.in = in;
            }
    
            @Override
            public void run() {
                try {
                    area.read(new InputStreamReader(in), null);
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
    
            }
        }
    }
    Attached Thumbnails Attached Thumbnails How display streamresults in JTextArea (Jlabel)-demo.png  
    Last edited by SurfMan; 11-14-2015 at 07:46 AM.
    gimbal2 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  15. #115
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    14

    Default Re: How display streamresults in JTextArea (Jlabel)

    Nice code - clean and speaks for itself.

    And still utterly useless to people who are in the copy/paste/don't need to understand market.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Page 6 of 6 FirstFirst ... 456

Similar Threads

  1. Dynamic Jlabel display
    By shashank.pr in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2013, 02:08 PM
  2. How can i display a number on a jlabel.
    By Shin in forum New To Java
    Replies: 4
    Last Post: 10-15-2012, 05:13 PM
  3. [Urgent Help] JLabel images display
    By baobao816 in forum AWT / Swing
    Replies: 2
    Last Post: 05-12-2012, 09:46 AM
  4. Display partial file contents in JTextArea
    By tmoehlman in forum New To Java
    Replies: 0
    Last Post: 11-02-2009, 11:03 PM
  5. Jtextarea Content Display Problem
    By REVANSIDDHA in forum Advanced Java
    Replies: 1
    Last Post: 03-31-2009, 06:53 PM

Tags for this Thread

Posting Permissions

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