问题
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