我正在開發使用Java NetBeans編輯器有點GUI應用程序的更改背景顏色。 我已經在JFrame中放入了一個簡單的進度條。 我開發的項目,JDK7雨雲L&F - 進度條
我想從默認的橙色背景顏色更改爲個人之一。我已經嘗試了顏色變化的所有屬性,但是當我運行該程序時顏色仍然相同。
我已經嘗試過使用 ProgressBar1.setBackground(new java.awt.Color(0,204,255));
和
UIManager.put("ProgressBar.background", Color.YELLOW);
UIManager.put("ProgressBar.foreground", Color.MAGENTA);
UIManager.put("ProgressBar.selectionBackground", Color.red);
UIManager.put("ProgressBar.selectionForeground", Color.green);
同樣的結果.....背景始終是橙色
這裏我的測試項目
public class Frame extends javax.swing.JFrame
{
public Frame()
{
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jProgressBar1 = new javax.swing.JProgressBar();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jProgressBar1.setBackground(new java.awt.Color(0, 204, 255));
jProgressBar1.setValue(75);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
public static void main(String args[])
{
try
{
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Frame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JProgressBar jProgressBar1;
// End of variables declaration
}
的代碼,這是當你啓動結果代碼 progress bar http://img1.uploadscreenshot.com/images/orig/8/21508073887-orig.jpg
橙顏色....
編輯 用下面的代碼
UIManager.getLookAndFeelDefaults().put("ProgressBar[Enabled].backgroundPainter", new FillPainter(Color.MAGENTA));
UIManager.getLookAndFeelDefaults().put("ProgressBar[Disabled].backgroundPainter", new FillPainter(Color.MAGENTA));
UIManager.getLookAndFeelDefaults().put("ProgressBar[Enabled+Indeterminate].progressPadding", new FillPainter(Color.ORANGE));
UIManager.getLookAndFeelDefaults().put("ProgressBar[Enabled].foregroundPainter", new FillPainter(Color.GREEN));
UIManager.getLookAndFeelDefaults().put("ProgressBar[Disabled].foregroundPainter", new FillPainter(Color.GREEN));
UIManager.getLookAndFeelDefaults().put("ProgressBar[Enabled+Finished].foregroundPainter", new FillPainter(Color.GREEN));
UIManager.getLookAndFeelDefaults().put("ProgressBar[Disabled+Finished].foregroundPainter", new FillPainter(Color.GREEN));
UIManager.getLookAndFeelDefaults().put("ProgressBar[Disabled+Indeterminate].foregroundPainter", new FillPainter(Color.GREEN));
UIManager.getLookAndFeelDefaults().put("ProgressBar[Enabled+Indeterminate].foregroundPainter", new FillPainter(Color.GREEN)); `
此行
javax.swing.UIManager.setLookAndFeel(info.getClassName());
後,我已經成功地改變背景顏色。 但現在的顏色是「普通」,有喜歡的橙色沒有梯度。
progress bar http://img1.uploadscreenshot.com/images/orig/8/21508411677-orig.jpg
是否有可能改變顏色與原來的顏色一樣的效果?
我認爲這是您使用的LaF的問題。只是片刻,我正在進行一些測試。從我在這個世界的角落 – davidbuzatto 2012-08-03 20:42:20
@Andrew湯普森是一位SSCCE non_accesible,或者我squid_proxy再有問題 – mKorbel 2012-08-03 20:46:41
我在這裏編輯您的文章,並添加代碼,請回復的變化,如果......,問題可以清楚交代現在 – mKorbel 2012-08-03 21:23:02