简体   繁体   English

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

[英]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");我需要弹出一个文本,就像你用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?我该怎么做?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM