我试图在变量中累积一个字符串,但制表符和换行符没有生效。
这是我的代码:
String message = "";
for(int i=1; i<=5; i++)
{
message += i +"\t";
}
JOptionPane.showMessageDialog(null, message);
它只显示:
1 2 3 4 5
代替数字之间的制表符
最佳答案
如下所示将消息放入 JTextArea。
String message = "";
for(int i=1; i<=5; i++){
message += i +"\t";
}
JOptionPane.showMessageDialog(null, new JTextArea(message));
关于java - 字符串变量中的\t 和\n 不显示在 JOptionPane.showMessageDialog 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9612880/