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

2022-09-03 09:43:27

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

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

我该怎么做?


答案 1

你可以像这样使用“\n”:

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

答案 2

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

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);