我想创建一个包含一些文本的JLabel。文字后面应该有一个栏。条的宽度应取决于一些外部参数。 JLabels的基本HTML支持是否可以做到这一点?
Mockup
最佳答案
也许可以,但我不会那样做,我会使用JProgressBar
来创建该栏,因为它甚至支持在其上绘制的字符串。有关更多详细信息,请参见this question。
简而言之:
// Do this when initializing:
yourProgressBar.setStringPainted(true);
// When you want to update it:
yourProgressBar.setValue(theCurrentValueAsInt);
yourProgressbar.setString(theCurrentValueAsString); // That can be any string.