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");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        textArea.setEditable(false);
        //... 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.pack();
        frame.setVisible(true);
        frame.add(textArea);
        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() {
		        textArea.append(text);
		      }
		    });
		  }

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

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

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

		    System.setOut(new PrintStream(out, true));
		    System.setErr(new PrintStream(out, true));
		  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.