1 我正在嘗試更改進度條的顏色,但它保持橙色這是代碼:
test(){
UIManager.put("ProgressBar.background", Color.BLACK);
UIManager.put("ProgressBar.foreground", Color.RED);
UIManager.put("ProgressBar.selectionBackground", Color.YELLOW);
UIManager.put("ProgressBar.selectionForeground", Color.BLUE);
bar = new JProgressBar();
bar.setBounds(20, 30,400 , 200);
bar.setString("Welcome...");
bar.setStringPainted(true);
this.add(bar);
我試過 .setbackground 它也沒有用
uj5u.com熱心網友回復:
您的代碼問題可能與您呼叫的位置有關UIManager。如果在物件初始化之前呼叫它,它可以正常作業:
UIManager.put("ProgressBar.background", Color.GREEN);
UIManager.put("ProgressBar.foreground", Color.BLUE);
UIManager.put("ProgressBar.selectionBackground", Color.RED);
UIManager.put("ProgressBar.selectionForeground", Color.GREEN);
JProgressBar progress = new JProgressBar();
結果:

如果您UIManager在初始化后呼叫,結果會有所不同:
JProgressBar progress = new JProgressBar();
UIManager.put("ProgressBar.background", Color.GREEN);
UIManager.put("ProgressBar.foreground", Color.BLUE);
UIManager.put("ProgressBar.selectionBackground", Color.RED);
UIManager.put("ProgressBar.selectionForeground", Color.GREEN);
結果:
] 2
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/457797.html
