Without even looking at the Javadoc for javax.swing.JTextPane, I can guess that setText() overwrites what is currently in the text pane with the new
String you pass it. That means, you are setting the text pane to contain, "hi" on the first run through the loop, overwriting "hi" with "how" on the second run, then "how" with "are", etc. There's no addText() method in JTextPane, so you could combine calls to getText() with String concantenation, like: pane.setText(pane.getText() + s);
Better yet, you could concatenate all the text using a StringBuilder, then set it all to the text pane after the loop. Also note that readLine() takes away line separators, so you'll have to add those back in manually, or add white space. Otherwise you'll get "hihowareyou".