我有这些进度条:
我正在尝试设置进度条 TEXT 的颜色,而不更改背景颜色或进度条本身的颜色。据我所知, setForeground() 设置文本和条形颜色?有没有办法做到一个没有另一个?
我有这些进度条:
我正在尝试设置进度条 TEXT 的颜色,而不更改背景颜色或进度条本身的颜色。据我所知, setForeground() 设置文本和条形颜色?有没有办法做到一个没有另一个?
啊哈 - 看起来我可以修改 UI:
setUI(new BasicProgressBarUI() {
protected Color getSelectionBackground() { return Color.black; }
protected Color getSelectionForeground() { return Color.white; }
});
这有点令人困惑,因为前景和背景的使用并不直观。背景是条不覆盖时文本的颜色,前景是条覆盖时文本的颜色。
这是最终结果:
通过带有 UIDefaults 的消息,
ProgressBar.background is the background color
ProgressBar.foreground is the cell color
ProgressBar.selectionBackground is the text color outside cells
ProgressBar.selectionForeground is the text colot INSIDE cells
UIManager.put("ProgressBar.selectionForeground", Color.black);
UIManager.put("ProgressBar.selectionBackground", Color.black);