Java Swing JFrame Background is not showing

强颜欢笑 提交于 2019-12-05 19:32:47
trashgod

The background color of a JProgressBar is determined by its UI delegate, ProgressBarUI. For example,

UIManager.put("ProgressBar.background", Color.red);

Not all implementations use the color; for example, com.apple.laf.AquaProgressBarUI ignores the setting in favor of the appearance seen here. As an alternative, you may want to consider a tinted background or Border on the enclosing panel, as suggested here.

Also note that you can update the GUI from the process() method, as shown here.

A few ideas:

  1. You're not supposed to add components directly to a JFrame. Instead, your content should go in the "content pane". See JFrame.setContentPane(), JFrame.getContentPane(). You may want refer to the JFrame documentation or a tutorial.

  2. If a component is not opaque, then its background will not be rendered. See JComponent.setOpaque(), Component.isOpaque().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!