更改 Swing 进度条的外观
我一直在尝试更改 UIManager 以使这些看起来愚蠢的绿色方块消失。我如何改变用户的外观和感觉?是否依赖于系统?其他正在编译我的代码的人有一个恒定的梯度。理想情况下,它只是一个实心正方形,而不是较小的块。
谢谢
I keep trying to chang the UIManager to make these stupid looking green squares go away. how do i change the look and feel of this to the user? Is it system dependent? Someone else who was compiling my code had a constant gradient. Ideally, it would just be a solid square, as opposed to smaller blocks.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过将其设置为系统(用户)的外观和感觉?
设置外观的最简单方法是在调用后启动 GUI:
话虽如此,上面似乎是 Windows XP 主题,并且确实可能是系统(用户)主题。我通常会远离 GUI 中的自定义主题,除非有非常的充分理由(例如,客户/用户要求)。
也就是说,上面的代码使其依赖于系统,这是好,因为它符合用户的期望。
Have you tried setting it to the system's (user's) look and feel?
The easiest way to set the look and feel is by launching the GUI after calling:
With that said, the above appears to be the Windows XP theme and may indeed be the system (user) theme. I generally stay away from custom themes in GUIs unless there is a very good reason (e.g., customer/user requirement).
That is to say, the above code makes it system dependent, which is good because it matches the user's expecations.
“这些看起来愚蠢的绿色方块”是 Windows XP 的外观和感觉的元素。如果您希望它们看起来不同,您可以更改此特定组件的外观和感觉。
只需使用下面的解决方法:
我使用此代码为 JFileChooser 提供另一种外观,并且它工作得很好。
您只需在创建组件之前更改外观和感觉,并在创建之后恢复前一个组件。
"These stupid looking green squares" are element of Windows XP's Look nad Feel. If you want them to look different, you can change Look and Feel for this particular component.
Just use below workaround:
I'm using this code for giving JFileChooser another look and it works perfectly.
You just change Look and Feel before creating component, and restoring previous one, just after that creation.
编辑
下面的代码更改了整个 JFrame 的 L&F。
第二:
在我看来(通过谷歌搜索并根据经验),在附加新的 L&F 时不可能只影响一个 JComponent。您可以在整个 JFrame 中更改 L&F,或者您可以 编写您自己的 Swing 组件。
实现目标的另一种方法是学习 java 源代码 并找到 JProgressBar 图像被添加到组件的位置,并通过扩展 JProgressBar 覆盖此方法。
Edit
Code below change the L&F of entire JFrame.
Secundo:
In my opinion (googled a lot and by expirience) it's impossible to affect only one JComponent while you attach a new L&F. You change your L&F in entire JFrame or you can Write your own Swing Component.
Another way to achive your goal is studying java source code and find place where JProgressBar image is beeing added to component and override this method by extending JProgressBar.
Java 外观和感觉的全面描述可以在 Sun Java 文档中找到,此处:Java、外观和感觉设计指南pdf 中的。
A comprehensive description of Java look and feel could be found by Sun Java document, here: Java, Look and Feel Design Guidelines in pdf.