GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes selection color for buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "selection color for buttons" Watch "selection color for buttons" New topic
Author

selection color for buttons

Ana Mihailescu
Greenhorn

Joined: Apr 26, 2001
Posts: 29
Hi,
I have the following problem:
I have more JButtons and I want them to have a different color when are pressed. For this, I do
UIManager.put("Button.select",java.awt.Color.red);
buton1.updateUI();
and it works if I want the same color for all the buttons.
But if I try to change the color and to make updateUI() for a second button, it changes also the color for the first button.
So, what can I do if I want to have different colors for differnt buttons whent they are selected ?
Thank you,
Ana
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
You can change the color of individual buttons by doing a
JButton.setBackground(Color)
in the actionPerformed() method of the button's action listener.
For example, this code is a JButton that is one of two colors, depending on various conditions:

Originally posted by Ana Mihailescu:
Hi,
I have the following problem:
I have more JButtons and I want them to have a different color when are pressed. For this, I do
UIManager.put("Button.select",java.awt.Color.red);
buton1.updateUI();
and it works if I want the same color for all the buttons.
But if I try to change the color and to make updateUI() for a second button, it changes also the color for the first button.
So, what can I do if I want to have different colors for differnt buttons whent they are selected ?
Thank you,
Ana


There's nothing more dangerous than a resourceful idiot. ---Dilbert
 
GeeCON Prague 2014
 
subject: selection color for buttons