Java: Multiple lines of text using JOptionPane.showInputDialog(null, "Text");

I need a text pop up like the one you get with JOptionPane.showInputDialog(null, "Text"); Just with multiple lines, like...

I'm new to java.
I have no background in programming.
I could use some help

How would I do this?

Answers


You could use '\n' like so:

JOptionPane.showMessageDialog(null, "Hello\nworld");

There's probably a dozen other ways to do this, but the simplest I can think of is

JOptionPane.showMessageDialog(null, "<html>I'm new to java.<br>I have no background in programming.<br>I could use some help Thanks!</html>");

Another approach to demonstrate the power of the JOptionPane

JTextArea msg = new JTextArea("This is a really silly example of what can be achieved with a JOptionPane, but this is going to excese for what you have asked for");
msg.setLineWrap(true);
msg.setWrapStyleWord(true);

JScrollPane scrollPane = new JScrollPane(msg);

JOptionPane.showMessageDialog(null, scrollPane);

Need Your Help

Attaching a listener to a cell and getting "out of memory" exception

excel vba

I have a sheet where I click a button. This button creates two forumla strings (which are C# excel addin/UDFs) and then pastes them into two cells. The first creates some data and stores it in the ...