JLabel上的制表空间没有显示 - 很奇怪 - Java [英] tab space on a JLabel not showing - weird - Java

查看:118
本文介绍了JLabel上的制表空间没有显示 - 很奇怪 - Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新文本更新JLabel,我需要此文本才能显示空格。

I'm trying to update a JLabel with new text and I need this text to have tabed space.

这是我的代码:

public void setNewLabelTxt(String text)
{
    nameLabel.setText(text + "\t");
}

标签已更新但最后没有标签空间我可以不知道为什么。据我所知 \t 是添加标签空间的方法。

The label is updated but there is no tab space at the end and I can't figure why. As far as I know \t is the way to add tab space.

推荐答案

JLabel 不以任何特殊方式呈现 \t (即,它不会转换渲染之前的 \t 到空格。)

JLabel doesn't render \t in any special way (ie, it doesn't convert the \t to spaces before rendering it).

相反,你应该使用像

text = text.replaceAll("\t", "    ");

在将其应用于标签之前。

Before applying it to the label.

这篇关于JLabel上的制表空间没有显示 - 很奇怪 - Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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