Change pressed button Color

Hi,
I want to change my pressed button Color and I haven't been able to find a way, I tried creating my own button and add a listener when it is pressed and then change its background color but it doesn't work! it works for enter and exit but not for pressed and released.
any one has an idea?
thanks
Here's my code:
package components;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.*;
* JButton con una nueva propiedad de Color presionado
* @author Ana Mar�a Franco
* @version 1.0
public class PressedColorButton extends JButton
    // Atributos ************************************************************************
    private Color unpressedButtonColor;
    private Color pressedButtonColor;
    // Constructores ********************************************************************
    public PressedColorButton()
        super();
        this.addMouseListener(new PressedColorButton_this_mouseAdapter(this));
    // M�todos **************************************************************************
     * Obtiene el color sin presionar
     * @return Color
    public Color getUnpressedButtonColor()
        return this.unpressedButtonColor;
     * Define el color sin presionar
     * @param nuevoColor Color
    public void setUnpressedButtonColor(Color nuevoColor)
        this.unpressedButtonColor = nuevoColor;
     * Obtiene el color presionado
     * @return Color
    public Color getPressedButtonColor()
        return this.pressedButtonColor;
     * Define el color presionado
     * @param nuevoColor Color
    public void setPressedButtonColor(Color nuevoColor)
        this.pressedButtonColor = nuevoColor;
    public void this_mouseExited(MouseEvent e)
        this.setBackground(unpressedButtonColor);
    public void this_mousePressed(MouseEvent e)
        this.setBackground(pressedButtonColor);
    public void this_mouseReleased(MouseEvent e)
        this.setBackground(unpressedButtonColor);
    public void this_mouseEntered(MouseEvent e)
        this.setBackground(pressedButtonColor);
// Escuchadores *************************************************************************
class PressedColorButton_this_mouseAdapter extends MouseAdapter
    private PressedColorButton adaptee;
    PressedColorButton_this_mouseAdapter(PressedColorButton adaptee)
        this.adaptee = adaptee;
    public void mouseExited(MouseEvent e)
        adaptee.this_mouseExited(e);
    public void mousePressed(MouseEvent e)
        adaptee.this_mousePressed(e);
    public void mouseReleased(MouseEvent e)
        adaptee.this_mouseReleased(e);
    public void mouseEntered(MouseEvent e)
        adaptee.this_mouseEntered(e);
}

Swing related questions should be posted in the Swing forum. Try setting the following properties on the button:
setContentAreaFilled( false );
setOpaque(true);

Similar Messages

  • Changing simple button color

    It would seem as if this would be simple, but I'm not finding
    any documentation.
    I have a map of the US. Each U.S. state is a simple button.
    I'd like to change the button fill color (and potentially, the
    outline color) in AS3. I've created the buttons in Flash, not in
    AS3 (just graphically). How do I change the button fill color?
    Sample code:
    function addButtonListeners(btnInstance:SimpleButton) {
    btnInstance.addEventListener( MouseEvent.ROLL_OVER,
    handleRollover);
    btnInstance.addEventListener( MouseEvent.ROLL_OUT,
    handleRollover);
    addButtonListeners(Montana);
    addButtonListeners(NewMexico);
    addButtonListeners(Washington);
    Montana._color = 0xA6CsDA; //doesn't work

    I also tried this code, but I'm getting the error message:
    Access of possibly undefined property rgb through a reference
    with static type flash.geom:ColorTransform.
    Source: color.rgb = 0x00ff00;

  • Changing radio button colors

    When hovering over a radio button, how do you change the fill color of the radio button? The default appears to be a shaded orange, but I want the flexibility to change colors, as needed.
    Any suggestions?
    Thanks!
    jason@jones

    Try using the setBackground or setForeground methods. If that doesn't work, look through the docs for any other methods that change the color. If those don't work, look into writing a custom ui component, which is not trivial.

  • Pressed button color

    Hi,
    I have a JPopUpMenu containing JMenuItems. When it is pressed, I would like the JMenuItem to freeze for some time and change color. I freeze it with a simple Thread.sleep(time). My problem is to change the color.
    If I try to change the display in the actionPerformed, the HMI is not updated before the end of the actionPerformed, so the menu disappears.
    I tried to use the UIManager with "menuPressedItemB" and "menuPressedItemF" that I found here:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=183858
    But it looks effectless...
    Any help is welcome. Thx for your attention,
    lolo

    Swing related questions should be posted in the Swing forum. Try setting the following properties on the button:
    setContentAreaFilled( false );
    setOpaque(true);

  • Can you change the button color on a custom theme?

    I recently installed a nice theme called Fractal-01 Song of a morning breeze. I had to installan add-on to change the menus that were white and thus invisible, but I have not figured out how to get the grey buttons for like Home and Back and Reload black, and they are very hard to see with this theme.
    I tried changing them in Custom Theme Restorer, but nothing seems to change them to black. I can't imagine that the person who designed this theme would have made these washed out colors that blend into the theme the default, but maybe he or she did. It is a shame to give up on such a nice theme if I don't have to, but it helps if you can see your buttons.

    Hi sherylz,
    It is also possible to edit the theme, but it may be wise to make a copy of it:
    *[https://support.mozilla.org/en-US/questions/940165]
    *[https://developer.mozilla.org/en-US/Add-ons/Themes/Background MDN Reference]
    *Add on to make own skin: [https://addons.mozilla.org/en-Us/firefox/addon/bt-canvas/]

  • Button Color

    Hi !
    My program endlessly scans a jTable of 150 row indexes in lenth.
    This jTable directly relates to 150 jButtons ... that depending on the status of thier function at any given time ... each change in color to reflect thier status. The buttons change in color 6 times ie; RED, GREEN, YELLOW,BLUE, GRAY or BLACK.
    Currently I change the button color in this way :
    import java.awt.Color;
    //import .*;
    * @author  Rick
    public class ButtonColorYellow {
        /** Creates a new instance of ButtonColorYellow */
        public ButtonColorYellow() {
            String  F0 = AddRFSwitchMain.jButton500.getText(); // Source of the Room Numbers that equate to the jButtons
              if (F0.equals("101")){
                AddRFSwitchMain.jButton101.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("102")){
                AddRFSwitchMain.jButton102.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("103")){
                AddRFSwitchMain.jButton103.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("104")){
                AddRFSwitchMain.jButton104.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("105")){
                AddRFSwitchMain.jButton105.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("106")){
                AddRFSwitchMain.jButton106.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("107")){
                AddRFSwitchMain.jButton107.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("108")){
                AddRFSwitchMain.jButton108.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("109")){
                AddRFSwitchMain.jButton109.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("110")){
                AddRFSwitchMain.jButton110.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("111")){
                AddRFSwitchMain.jButton111.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("112")){
                AddRFSwitchMain.jButton112.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("113")){
                AddRFSwitchMain.jButton113.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("114")){
                AddRFSwitchMain.jButton114.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("115")){
                AddRFSwitchMain.jButton115.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("116")){
                AddRFSwitchMain.jButton116.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("117")){
                AddRFSwitchMain.jButton117.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("118")){
                AddRFSwitchMain.jButton118.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("119")){
                AddRFSwitchMain.jButton119.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("120")){
                AddRFSwitchMain.jButton120.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("121")){
                AddRFSwitchMain.jButton121.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("122")){
                AddRFSwitchMain.jButton122.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("123")){
                AddRFSwitchMain.jButton123.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("124")){
                AddRFSwitchMain.jButton124.setBackground(new Color(255,255,0)); // Yellow Color
            } if (F0.equals("125")){
    ..................  etc, etc, etc   ( room numbers are used for index references ie: 101,102, 103, etc)This code works well , but would think there must be a better wat to code it.
    I will make the color itself a var like this:
    AddRFSwitchMain.jButton124.setBackground(new Color( a , b , c ));...... but is there any way to adress the JButtons themselves in a var way??
    ie:
    AddRFSwitchMain.jButton( var X ).setBackground(new Color( a , b , c ));I know ya cant change the jButton lable itself ... but any way to reference the buttons in a like fashion ??
    THANKS !!

    You currently are creating 150 separate buttons each
    independent and unrelated to each other. I would
    reccomend creating an two arrays, one of buttons, and
    another of button status which you can then loop
    thorugh and change with logic
    Something like this:
    Button[] myButtonArray
    int[] myButtonStatus
    init() {
    Button[] myButtonArray = new Button[150];
    int myButtonStatus = new int[150];
    for (int i = 0; i < 150 ; i++)
    myButtonArray[i] = new Button("Button #" +
    n #" + (i + 1) );
    myButonStatus[i] = ** Get Status from
    tus from jTable
    then in Main Code soemthing like
    for (int i=0 ; i < 150 ; i++)
    if (myButtonStatus = 101) then
    ) then
    {myButtonArray.setBackGround(Color.Yellow);
    if (myButtonStatus = xyz ) then
    {myButtonArray[i].setBackGrondr(Color.Black);
    Hope this helps
    JavaPython ....
    Does not your code snip make for 150 lines of code entry listed below? : (
    if (myButtonStatus = 101) then
    ) then
    {myButtonArray.setBackGround(Color.Yellow);
    if (myButtonStatus = 101) then
    ) then
    {myButtonArray.setBackGround(Color.Yellow);

  • How to change the button colour automatically????

    i want to change the button color automatically ,if there is no data in next page ....plzz help

    Hi,
    create a binding for the data collection displayed on next page and do
    styleClass=#{bindings.iterator.estimatedRowCount<=0?'redClass' : ''}
    Then define a custom skin (see how to skin an application in the web developer guide) and use
    .redClass .af|commandButton{background-color:red}
    in this skin. Now when the page renders or when you PPR the button, the color should apply or not. Btw, the same EL on the disabled property or the rendered property would do the same trick (probably better than just a color change)
    Frank

  • How to change button colors in a loop?

    I am working on a task that should imitate an elevator. I have two vertical
    rows of round buttons "Up" and "Down" When a circle is selected randomly by
    the program, the circle becomes yellow and the elevator moves to that
    button.
    Here is what I did:
    1. created a class Circle where I save buttons' parameters
    2. saved Circle objects in an array
    3. drew the buttons depending on their parameters
    4. generated a random number, matched it with an array index and assigned
    the object color to yellow.
    Everything is fine except that I can't figure out how to change colors of my
    buttons in a loop.
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class Elevator3 extends JPanel
    private int n = 40;
    private int width = 200;
    private int floors = 10;
    private int interval = 1000;
    private boolean selected = false;
    private Circle[] buttons = new Circle[2*(floors-1)];
    public Elevator3()
    build();
    JFrame frame = new JFrame("Elevator3");
    setBackground(Color.WHITE);
    setFont(new Font("SansSerif", Font.PLAIN, Math.round(n/3)));
    frame.getContentPane().add(this);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(width, n*(floors+2) );
    frame.setVisible(true);
    public void build()
    Random r = new Random();
    int buttonPick;
    int timeUntilNextButton = r.nextInt(interval);
    for (int k =0; ; k++)
    if (timeUntilNextButton-- ==0)
    buttonPick = r.nextInt(2*(floors-1));
    //populate my buttons array here - how??
    timeUntilNextButton = r.nextInt(interval);
    //adding "Down" buttons
    for (int i=1, count=0; i < floors; i++, count++)
    if (count == buttonPick)
    selected = true;
    else
    selected = false;
    buttons[count]= new Circle(n*2, n*i, selected, Math.round(n/2));
    //build an array of "Up" circles
    for (int i=2, count=floors-1; i < floors+1; i++, count++)
    if (count == buttonPick)
    selected = true;
    else
    selected = false;
    buttons[count]= new Circle(n, n*i, selected, Math.round(n/2));
    public static void main(String[] args)
    new Elevator3();
    protected void paintComponent(Graphics g)
    super.paintComponent(g);
    //draw buttons
    for (int i=0; i < buttons.length; i++)
    g.setColor(buttons.getColor());
    g.fillOval(buttons[i].getX(), buttons[i].getY(), buttons[i].getWidth(), buttons[i].getWidth());
    class Circle
    private int x;
    private int y;
    private Color c;
    private boolean pressed;
    private int width;
    public Circle(int xCoordinate, int yCoordinate, boolean selected, int diameter)
    x = xCoordinate;
    y = yCoordinate;
    pressed = selected;
    width = diameter;
    if (pressed)
    c = Color.YELLOW;
    else
    c = Color.LIGHT_GRAY;
    public Color getColor()
    return c;
    public int getX()
    return x;
    public int getY()
    return y;
    public int getWidth()
    return width;

    hi,
    am sorry, i couldn't make out what exactly the problem, but as ur subject line says...
    may be the code give below will help you to change button colors in a loop..
              for(int i = 0; i < button.length; i++){
                   int color1 = (int)(250*Math.random());
                   int color2 = (int)(250*Math.random());
                   int color3 = (int)(250*Math.random());
                   Color c = new Color(color1,color2,color3);
                   button[i] = new JButton("button name");
                   button.addActionListener(this);
                   //to check the r, g, b combination.
                   //System.out.println(c);
                   button[i].setBackground(c);
                   button[i].setForeground(Color.white);
    //adding into the panel
                   panel.add(button[i]);
    hope this would help you.

  • How to change the background color of a button when the button is emphasized

    Hi,
    I have a button that is in the "emphasized" state, I realized there is a default color "light blue" when the button is emphasized. is there any way I can change this default color? so if mu button goes to emphasized state I can control which color it should be
    I am using "Halo" for the theme, and I was not able to change the Focus color through the "Appearance Window" in Flash Builder 4
    any help would be appreciated

    Take a look at the accentColor flag of <s:Button>. It looks like you can do it there. But, it also looks like emphasized needs to be "true" and that you may need to interrupt the button's automatic update event... I've never tried to do this though. And, I imagine you only need to listen to button state changes if you want to dynamically control the emphasized color. If you just want to set a static value other than the default, it looks like setting emphasized to true and the uint of the accentColor will do the trick...

  • Changing the button fill color in Captivate 7?

    I am pretty sure that when I used Captivate 6 and I created a button, there was an option in the Properties pane to allow me to change the fill color of the button. I am using Captivate 7 now, and I no longer see this option. Under the "General" tab, it allows me to change the button type, caption, make it transparent, or allows me to see button widgets. Did they remove the ability to simply change the fill color of a button?

    I'm wondering if this is something that was maybe added in a service release. Either that or you may need to reset your preferences.
    Mine has a section titled Fill & Stroke as shown below.
    Cheers... Rick

  • Change the background color in a button

    I want to change the background color in a button that have a text(It not have an icon).
    DO you know how to do it?

    Hi suasna
    i have a solution for your ask actually i did when i wanted to change the bgcolor of a button ....but i this case u need to use Icon editor to create the icon with the color u want and add to it the text u want to apply ...then set the inconic ptoperty of the button to YES and set the Icon name that u have created with the software ..
    hope this helps u
    thanks

  • How to change the button's clicked color

    Dear all,
    How to change the button's clicked color
    I want it to be white in color as my button's background color is white
    Thanks

    How to change the button's clicked colorvia the UIManager

  • Is there any way to change the color of the Firefox 4 menu button away from orange? It attracts my attention and as far as I can tell personas change everything but the menu button color.

    Is there any way to change the color of the Firefox 4 menu button away from orange? It attracts my attention and as far as I can tell personas change everything but the menu button color.

    You can change it with the App Button Color extension - https://addons.mozilla.org/firefox/addon/app-button-color

  • Change button color

    i have a group of buttons and when each one is clicked its color should change. when another button is clicked the color of previous button should change back to normal..plz help..thanks in advance

    Hi Srivatsa,
    You can do the same for chnanging your button icons if you have only tow icons to display ....one is default icon and the other one is the icon which you wnat to display when the button is clicked...
    Check the below code:
    Just replace the image path in the embed variable with your image path and check...
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
      <![CDATA[
       private var previousButtonClicked:Button;
       [Embed("assets/Rose20Icon.jpg") ]
             [Bindable]private var buttonIcon:Class;
             [Embed("assets/arrowIcon.JPG") ]
             [Bindable]private var buttonIconDefault:Class;
       private function buttonClickHandler(event:MouseEvent):void
        if(previousButtonClicked)
         previousButtonClicked.setStyle("icon",buttonIconDefault);
        previousButtonClicked = event.currentTarget as Button;
        Button(event.currentTarget).setStyle("icon",buttonIcon);
      ]]>
    </mx:Script>
    <mx:HBox>
      <mx:Button id="btn1" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
      <mx:Button id="btn2" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
      <mx:Button id="btn3" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
      <mx:Button id="btn4" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
      <mx:Button id="btn5" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
      <mx:Button id="btn6" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
      <mx:Button id="btn7" icon="{buttonIconDefault}" label="Button" color="green" click="buttonClickHandler(event);"/>
    </mx:HBox>
    </mx:Application>
    Thanks,
    Bhasker Chari 

  • How to change web button and bars colors??

    is there anyway to change illustrators default web buttons and bars after they are dragged to the canvas. it seems a lot of the buttons are yellow or blue. i wanted to specifically change the color of a "talk bubble." thanks

    You haven't specified which version of Illustrator you are using, but I will assume for purposes of this discussion, that my version, CS3, is not vastly different from yours. The "Web Buttons and Bars" is a collection of symbols, which gives you several options. When you drag a symbol to the artboard three buttons appear in the Control Panel: Edit Symbol, Break Link, and Duplicate. Each affords you certain option for editing the symbol.
    Edit Symbol puts the symbol into Isolation Mode, which allows access to the parts of the symbol through the Layers Panel and the Appearance Panel, and may be changed using any colors, effects, transformations, additions, deletions, or anything else you choose to do to it. When you are finished editing, and exit Isolation Mode, the changes you have made will appear in the symbol in the Symbols Panel and in any instances of the symbol you have put on the artboard.
    Break Link turns the symbol instance you have selected into an object which may be changed in any manner you choose, just as if you had built it yourself and then changed your mind. Changes to the object will have no effect on other instances of the symbol, nor on the symbol in the Symbols Panel, because it is no longer a symbol and is completely unrelated to either. If you wish, you may turn the edited object into a new symbol.
    Duplicate turns the selected symbol instance into a new symbol, identical to the original but having no connection either to it nor to other instances of the original. If the first symbol was named "Original," then a new one will appear in the Symbols Panel named "Original 1." The same options will be available in the Control Panel, and any changes you make will only be applied to the new symbol and any instances of it that you may have put onto the artboard.
    You may save your edited symbols through the Symbols Library Menu in the Symbols Panel.
    If any of this is unclear, doesn't work, or is flat wrong, please let me know.
    Peter

Maybe you are looking for