Java:使用JOptionPane.showInputDialog(null,“Text”)的多行文本;

时间:2012-08-25 00:36:07

标签: java swing text

我需要弹出一个文字,就像你使用JOptionPane.showInputDialog(null, "Text");一样,只需多行,例如...

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

我该怎么做?

2 个答案:

答案 0 :(得分:17)

您可以像这样使用'\ n':

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

答案 1 :(得分:15)

可能有十几种其他方法可以做到这一点,但我能想到的最简单的方法是

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

另一种展示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);