Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

selection color for buttons

 
Ana Mihailescu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic