Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swing 设置JProgressBar文本的颜色_Swing_Jprogressbar - Fatal编程技术网

Swing 设置JProgressBar文本的颜色

Swing 设置JProgressBar文本的颜色,swing,jprogressbar,Swing,Jprogressbar,我有这些进度条: 我试图设置进度条文本的颜色,而不改变背景颜色或进度条本身的颜色。据我所知,set前台()同时设置文本和条颜色?有没有办法做到一个不做另一个?啊哈-看起来我可以修改UI: setUI(new BasicProgressBarUI() { protected Color getSelectionBackground() { return Color.black; } protected Color getSelectionForeground()

我有这些进度条:


我试图设置进度条文本的颜色,而不改变背景颜色或进度条本身的颜色。据我所知,set前台()同时设置文本和条颜色?有没有办法做到一个不做另一个?

啊哈-看起来我可以修改UI:

    setUI(new BasicProgressBarUI() {
      protected Color getSelectionBackground() { return Color.black; }
      protected Color getSelectionForeground() { return Color.white; }
    });
这有点混乱,因为前景和背景的使用并不直观。背景是条未覆盖时文本的颜色,前景是条未覆盖时文本的颜色

以下是最终结果:


通过带有默认值的消息

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);