最佳答案
尝试这个教学示例。它将修改 JProgressBar 的 4 种颜色。 可能有点难以看清文字颜色,但这是一张图像 预计。该栏为黑底红字,文本颜色为黄色和蓝色。
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.UIManager;
public class JProgressBarTest {
public static void main(final String[] args) {
UIManager.put("ProgressBar.background", Color.BLACK);
UIManager.put("ProgressBar.foreground", Color.RED);
UIManager.put("ProgressBar.selectionBackground", Color.YELLOW);
UIManager.put("ProgressBar.selectionForeground", Color.BLUE);
final JProgressBar progressBar = new JProgressBar();
new JFrame() {
{
getContentPane().setLayout(new FlowLayout());
getContentPane().add(progressBar);
progressBar.setValue(50);
progressBar.setStringPainted(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(400, 200);
setLocationRelativeTo(null);
setVisible(true);
}
};
}
}
关于java - JProgressBar 改变条形颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44165541/