How to change JProgressBar color?

后端 未结 2 1768
暗喜
暗喜 2020-11-28 15:10

I Used .setBackground and .setForeground and they didn\'t work, the color is like Orange, can\'t change it.

相关标签:
2条回答
  • 2020-11-28 15:32

    You should set the setStringPainted property to true:

    progressBar.setStringPainted(true);
    progressBar.setForeground(Color.blue);
    progressBar.setString("10%");
    
    0 讨论(0)
  • 2020-11-28 15:37

    I think that these values are right for you

    UIManager.put("ProgressBar.background", Color.ORANGE);
    UIManager.put("ProgressBar.foreground", Color.BLUE);
    UIManager.put("ProgressBar.selectionBackground", Color.RED);
    UIManager.put("ProgressBar.selectionForeground", Color.GREEN);
    
    0 讨论(0)
提交回复
热议问题