i磛e tried both getbackground and getforeground before changing it's color but the values i get are not from the Jbutton itself.
?ve heard that this light blue degrad?color that jbuttons initially have are from windows default and i supose that's the reason why the getbackground method ain't working in this situation..
thanxs for the reply anyway
cheers
Works for me:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonExample implements Runnable, ItemListener {
private JCheckBox red;
private JButton button;
private Color btnColor;
public void run() {
red = new JCheckBox("Color it red");
red.addItemListener(this);
button = new JButton("Some button");
btnColor = button.getBackground();
JPanel p = new JPanel();
p.add(red);
p.add(button);
JFrame f = new JFrame("ButtonExample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public void itemStateChanged(ItemEvent e) {
button.setBackground(e.getStateChange() == ItemEvent.SELECTED ? Color.RED : btnColor);
}
public static void main(String[] args) {
EventQueue.invokeLater(new ButtonExample());
}
}