0
String noun1 = jTextField1.getText();
        String noun2 = jTextField1.getText();
        String noun3 = jTextField1.getText();

        String verb1 = jTextField1.getText();
        String verb2 = jTextField1.getText();
        String verb3 = jTextField1.getText();

        String adj1 = jTextField1.getText();
        String adj2 = jTextField1.getText();
        String adj3 = jTextField1.getText();

        String story = "This is the story about a " + noun1;

        jTextArea1.setText(story);

I'm creating a Madlibs with JFrame and need to find out how to continue string on a new line (I forgot) Such as story. I need it to continue so I can add the other sentences.

Jokes
  • 49
  • 1
  • 9

2 Answers2

3

You mean a linebreak in the String? Then the code you are looking for is "\n". E.g. the output of

String text = "Hello \nWorld";

Would be

Hello
World
ctst
  • 1,610
  • 1
  • 13
  • 28
3

Use a line separator

String story = "This is the story about a" + System.lineSeparator() + noun1;

Or use \n for a new line

String story = "This is the story about a\n" + noun1;

Also you can use more System.out.println(...) commands when you want to print it out.

System.out.println("This is the story about a"); // Print the string inside and add a linebreak afterwards
System.out.println(noun1); // Print the value of noun1 variable

All of them will give you the following result:

This is the story about a
"your story name"

More information is here: Java String new line

Community
  • 1
  • 1
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183