字符串变量中的\ t和\n不会显示在JOptionPane.showMessageDialog中

use*_*352 1 java swing

我试图在变量中累积一个String,但tab和换行不会生效.

这是我的代码:

String message = "";

for(int i=1; i<=5; i++)
{
    message += i +"\t";
}

JOptionPane.showMessageDialog(null, message);
Run Code Online (Sandbox Code Playgroud)

它只显示:

1 2 3 4 5 
Run Code Online (Sandbox Code Playgroud)

而不是在数字之间有标签

nam*_*olk 8

将消息放入JTextArea,如下所示.

String message = "";

for(int i=1; i<=5; i++){
    message += i +"\t";
}
JOptionPane.showMessageDialog(null, new JTextArea(message));
Run Code Online (Sandbox Code Playgroud)