title: How to redirect all console output to a Swing JTextArea/JTextPane with the right encoding?
body: <p>I've been trying to redirect System.out PrintStream to a JTextPane. This works fine, except for the encoding of special locale characters. I found a lot of documentation about it (see for ex. <a href="http://mindprod.com/jgloss/encoding.html" rel="noreferrer">mindprod encoding page</a>), but I'm still fighting with it. Similar questions were posted in StackOverFlow, but the encoding wasn't addressed as far as I've seen.</p>
  
  <p>First solution:</p>
  
  <pre><code>String sUtf = new String(s.getBytes("cp1252"),"UTF-8");
  </code></pre>
  
  <p>Second solution should use java.nio. I don't understand how to use the Charset.</p>
  
  <pre><code>Charset defaultCharset = Charset.defaultCharset() ;
  byte[] b = s.getBytes();
  Charset cs = Charset.forName("UTF-8");
  ByteBuffer bb = ByteBuffer.wrap( b );
  CharBuffer cb = cs.decode( bb );
  String stringUtf = cb.toString();
  myTextPane.text = stringUtf
  </code></pre>
  
  <p>Neither solution works out. Any idea?</p>
  
  <p>Thanks in advance,
  jgran</p>