1

I have constructed a JTextArea, and added that to a JScrollPane and I want to add any output to the scroll pane. I have written this...

 outputText = new JTextArea(15, 40);
    outputText.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(outputText);
    contentPane.add(scrollPane, BorderLayout.CENTER);

I have already initialized the JTextArea in the constructor. I then write this...

public void println(String n)
{
    outputText.append(n + "\n");
    outputText.setCaretPosition(outputText.getText().length());
}

public void printWelcome()
{
    println("Welcome to my Program!");
    println("When you're done, press 'Done'. ");
}

But when I start my GUI, none of the text shows up. Suggestions?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
LynnLove
  • 29
  • 2
  • 8
  • 1
    Can you show a [mcve], please? Where's the code to initialize the Frame? – OneCricketeer Jun 04 '16 at 05:07
  • With the current amount of code you have posted and assuming that you call the `printWelcome()` method, _I can only guess_ it is because you are not calling `revalidate()` and `repaint()` on `outputText` after appending the text in the `println(String n)` function. – MasterBlaster Jun 04 '16 at 05:07
  • http://stackoverflow.com/questions/19212126/how-can-we-add-jscrollpane-on-jtextarea-in-java this post might help you. – Priyamal Jun 04 '16 at 05:13
  • U can try by using some other name for your method, using println is like overriding it. – Sukhbir Jun 04 '16 at 11:59

0 Answers0