Recovering JButton Original Color

hi there :)i was looking for a way that after changing a JButton background color, then to get the original light blue degrad?color again. is there any way to do that?thanxs in advancecheers
[218 byte] By [Ashenvalea] at [2007-11-27 8:58:27]
# 1
How about storing it somewhere first?
CeciNEstPasUnProgrammeura at 2007-7-12 21:24:31 > top of Java-index,Java Essentials,New To Java...
# 2

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

Ashenvalea at 2007-7-12 21:24:31 > top of Java-index,Java Essentials,New To Java...
# 3

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());

}

}

BigDaddyLoveHandlesa at 2007-7-12 21:24:31 > top of Java-index,Java Essentials,New To Java...
# 4
thanxs BigDaddyLoveHandles for the fast replywill try thisthanxs :)
Ashenvalea at 2007-7-12 21:24:31 > top of Java-index,Java Essentials,New To Java...