swing:制作一个 JProgressBar 并在其上叠加标签?
我想使用 JProgressBar 并对其进行扩充以打印其当前值以及图形栏。
我猜最好的方法是覆盖paintComponent:
@Override protected void paintComponent(Graphics g) {
// Let component paint first
super.paintComponent(g);
// paint my contents next....
}
但我不确定...有什么建议吗?
I would like to use a JProgressBar
and augment it to print its current value as well as the graphical bar.
I'm guessing the best way to do this is to override paintComponent:
@Override protected void paintComponent(Graphics g) {
// Let component paint first
super.paintComponent(g);
// paint my contents next....
}
but I am not sure... any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议你使用它自己的API:
和
参考总是一件好事。 :)
请注意,要在运行期间编辑值,您应该考虑将
ChangeListener
附加到进度栏。I would suggest you to use its own API:
and
Reference is always a good thing. :)
Mind that to enable editing the value during its run you should consider having a
ChangeListener
attached to the progress bar.基于杰克答案的工作解决方案:
Working solution based on Jack's answer: