如何改变JProgressBar的颜色
1我试图更改进度条的颜色,但它保持橙色,这是代码:
test(){
UIManager.put("ProgressBar.background", Color.BLACK);
UIManager.put("ProgressBar.foreground", Color.RED);
UIManager.put("ProgressBar.selectionBackground", Color.YELLOW);
UIManager.put("ProgressBar.selectionForeground", Color.BLUE);
bar = new JProgressBar();
bar.setBounds(20, 30,400 , 200);
bar.setString("Welcome...");
bar.setStringPainted(true);
this.add(bar);
我尝试了.setBackground,它也无法正常工作
1 I am trying to change the color of the progress bar but it stays orange here's the code:
test(){
UIManager.put("ProgressBar.background", Color.BLACK);
UIManager.put("ProgressBar.foreground", Color.RED);
UIManager.put("ProgressBar.selectionBackground", Color.YELLOW);
UIManager.put("ProgressBar.selectionForeground", Color.BLUE);
bar = new JProgressBar();
bar.setBounds(20, 30,400 , 200);
bar.setString("Welcome...");
bar.setStringPainted(true);
this.add(bar);
I've tried .setbackground it also didnt work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码问题可能与您调用
UIManager
的位置有关。如果在对象初始化之前调用它,它会正常工作:
结果:

,如果您在初始化后调用
UIManager
,结果将会有所不同:结果:
]2
the problem with your code might relate to the location which you called
UIManager
.if you call it before object initialization it works correctly:
result:

and if you call
UIManager
after initialization the result will differ:result:
]2