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

jjd*_*712 14 java swing text

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

I'm new to java.
I have no background in programming.
I could use some help
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

Dav*_*amp 17

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

JOptionPane.showMessageDialog(null, "Hello\nworld");
Run Code Online (Sandbox Code Playgroud)

  • -1 他想从用户那里获取输入文本(输入对话框看起来像一个文本区域),而不是向用户输出多行。 (3认同)

Mad*_*mer 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>");
Run Code Online (Sandbox Code Playgroud)

另一种证明力量的方法 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);
Run Code Online (Sandbox Code Playgroud)

  • @DavidKroukamp爱用Java编写HTML,希望它有更好的CSS支持 (3认同)