tab space on a JLabel not showing - weird - Java

可紊 提交于 2019-12-02 03:39:45

问题


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

This is my code:

public void setNewLabelTxt(String text)
{
    nameLabel.setText(text + "\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.


回答1:


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

Instead, you should use something like

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

Before applying it to the label.



来源:https://stackoverflow.com/questions/19897827/tab-space-on-a-jlabel-not-showing-weird-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!