字符串变量中的\t和\ n不会显示在JOptionPane.showMessageDialog中 [英] \t and \n in a String variable does not display in JOptionPane.showMessageDialog

查看:205
本文介绍了字符串变量中的\t和\ n不会显示在JOptionPane.showMessageDialog中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在变量中累积一个字符串,但制表符和换行符不会生效。

I am trying to accumulate a String in a variable but the tab and newline does not take effect.

这是我的代码:

String message = "";

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

JOptionPane.showMessageDialog(null, message);

它只显示:

1 2 3 4 5 

而不是在数字之间设置标签

instead of having tabs between the numbers

推荐答案

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

Put the message to the JTextArea as follows.

String message = "";

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

这篇关于字符串变量中的\t和\ n不会显示在JOptionPane.showMessageDialog中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆