15

我需要弹出一个文本,就像你JOptionPane.showInputDialog(null, "Text");用多行得到的那样,比如......

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

我该怎么做?

4

2 回答 2

18

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

JOptionPane.showMessageDialog(null, "Hello\nworld");
于 2012-08-25T00:41:27.617 回答
16

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

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);
于 2012-08-25T00:40:38.343 回答