title: How to create and use a JTextPane
body: <p>I would like to create a program in Java that it is done this way:
  <a href="https://i.stack.imgur.com/qRpY5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qRpY5.png" alt="What I want" /></a></p>
  <p>A window containing a button and a component (JTextArea, JTextPane, etc.) that can't be modified in which appear some strings based on the execution of some work.
  As seen from the drawing, if the job is successful the text will be black, if there were errors will be marked red.</p>
  <p>I managed to do everything correctly using a JTextArea and a JButton but I found that you can't change the color of the strings line by line.</p>
  <p>I read that should use a JTextPane but I haven't been able to use it.
  Here's the code I wrote:</p>
  <pre><code>public class Example {
  
     public Example() {
          JFrame frame = new JFrame();
          JTextPane pane = new JTextPane();
          JButton button = new JButton(&quot;Button&quot;);
      
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          pane.setPreferredSize(new Dimension(200, 200));
          frame.add(pane);
          frame.add(button);
          frame.pack();
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          new Example();
      }
  }
  </code></pre>
  <p>When I run the program, this is what is created:</p>
  <p><a href="https://i.stack.imgur.com/6IBzx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6IBzx.png" alt="enter image description here" /></a></p>
  <p>Where the TextPane?</p>
  <p>Also, before I added the text in JTextArea using append(), I haven't found a similar method to the JTextPane there? How do you use it?
  How do I change the color of a single line?</p>
  <p>I have read and seen and tried various examples found on the internet but I could not finish anything...
  There are worked examples similar to this?</p>
  <p>I apologize for the &quot;generic&quot; request...</p>
  <p>Thanks</p>