I'm creating an NBT viewer in Java. It works fine as a console application so I used code to rewrite all console (system.out.println) text to GUI text. It works but it does not use scrollbars correctly.

Here is my code (For my window/GUI void)

private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("NBT Viewer Alpha 0.2");
        //... Set textarea's initial text, scrolling, and border.

        JScrollPane scrollPane = new  JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane. HORIZONTAL_SCROLLBAR_AS_NEEDED);
        //... Get the content pane, set layout, add to center
        frame.setLayout(new BorderLayout());
        frame.add(scrollPane, BorderLayout.CENTER);
        //Display the window.
        frame.add(scrollPane, BorderLayout.CENTER);
        //... Set textarea's initial text, scrolling, and border.


Yes the code does create a scrollbar but it is unused. Please help? :S

And in-case you're curious about the console-to-GUI thing...

private static void updateTextArea(final String text) {
		    SwingUtilities.invokeLater(new Runnable() {
		      public void run() {

		  private static void redirectSystemStreams() {
		    OutputStream out = new OutputStream() {
		      public void write(int b) throws IOException {
		        updateTextArea(String.valueOf((char) b));

		      public void write(byte[] b, int off, int len) throws IOException {
		        updateTextArea(new String(b, off, len));

		      public void write(byte[] b) throws IOException {
		        write(b, 0, b.length);

		    System.setOut(new PrintStream(out, true));
		    System.setErr(new PrintStream(out, true));
This article has been dead for over six months. Start a new discussion instead.