i'm developing a little GUI application with Java using Netbeans Editor. I've put in a JFrame a simple Progress Bar. I'm developing the project with JDK7
I want to change the background Color from default Orange to a personal one. I've already tried all the properties for the color changing but when i run the program the color still the same.
I've already tried using ProgressBar1.setBackground(new java.awt.Color(0, 204, 255));
and
UIManager.put("ProgressBar.background", Color.YELLOW);
UIManager.put("ProgressBar.foreground", Color.MAGENTA);
UIManager.put("ProgressBar.selectionBackground", Color.red);
UIManager.put("ProgressBar.selectionForeground", Color.green);
Same result..... The background is always orange
Here the code of my test project
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
}
and this is the result when you launch the code
(source: uploadscreenshot.com)
Orange color....
EDIT With the following code
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)); `
after this line
javax.swing.UIManager.setLookAndFeel(info.getClassName());
I've successfully change the color of background. But now the color is "plain", there is no gradient like the orange color.
(source: uploadscreenshot.com)
Is it possible to change color with the same effect of the original color?