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

Similar Messages

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

  • 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.

  • Button color used make it other button next

    Hello ppl :-)
    i got 3 Radiobuttons 
    1 makes it blue 
    1 makes it red
    1 makes it white 
    got 4 buttons 
    i have made it so if i press button 1 it moves to button 4
    the problem is i want it to if buttons 4 is blue 
    and i select blue or red by radiobuttons again clicking button 1 and it should
    auto put it in button 3 becuse button 4 is full 
    and again if i pick radiobutton ( white ) click button 4 
    so it clears .... 
    it should move button 3-2-1 becuse they are full to 4-3-2
    leaveing button 1 clear 
    any 1 got some ideas would be great 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If RadioButton1.Checked Then
    Button1.BackColor = Color.Blue
    End If
    If RadioButton2.Checked Then
    Button1.BackColor = Color.Red
    End If
    If RadioButton3.Checked Then
    Button1.BackColor = Color.White
    End If
    Dim colour As Color = Button2.BackColor
    Button2.BackColor = Button1.BackColor
    Button1.BackColor = colour
    Button3.BackColor = Button2.BackColor
    Button2.BackColor = colour
    Button4.BackColor = Button3.BackColor
    Button3.BackColor = colour
    My.Settings.Save()
    End Sub

    The description is unclear you saying: 
    "if buttons 4 is blue 
    and i select blue or red by radiobuttons again clicking button 1 and it should
    auto put it in button 3 becuse button 4 is full :"
    What if red is selected why don't you change the button 3 and 4 to red?
    Also I would like to suggest another scenario is to fire the event when changing the values of the radios and not on clicking button1. For example if I have two radios Red and Blue I will put them both in a GroupBox control(you may need to right click the group
    box and click send to back if you add it after the radios to the form):
    and also in the "Tag" property of of the radio I will add the related color name to it (to add the tag property select the radio button and go to properties and fill the Tag with the related color: Red for example".
    Then on ChekcedChanged event of the radios I will be able to read that Tag value and convert it to color and then assign to the button.
    Events example:
    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
    If RadioButton1.Checked = True Then
    Dim clr As Color = Color.FromName(RadioButton1.Tag)
    Button1.BackColor = clr
    End If
    End Sub
    Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
    If RadioButton2.Checked = True Then
    Dim clr As Color = Color.FromName(RadioButton2.Tag)
    Button1.BackColor = clr
    End If
    End Sub
    Fouad Roumieh

  • Help with getting button color.

    I'm trying to make a little paint program. i want to be able to click on a color button and then assign the color of that button to a variable Color brushColor.
    funny thing is, when i compile this, it tells me that
    C:\java\javaprograms\TryPainting.java:21: getBackground() in java.awt.Component cannot be applied to (java.awt.Button)
              brushColor = paintTheBrush(getBackground(source));
    strange, getBackground is explicitly listed as a method that Button inherits from Component in the API.
    any suggestions on a way to accomplish this?
    thanks in advance,
    jason
    ------code follows-------
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    //colored buttons of "paint"
    class OilPaint extends Button{
    Color brushColor = Color.white;
    OilPaint(String label, Color color) {
         setLabel(label);
         setForeground(color);
         setBackground(color);
         addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
         Button source = (Button)e.getSource();
         brushColor = getBackground(source);
         public Color paintTheBrush(Color color) {
              return color;
    // canvas to paint on - this isn't working yet. can't even get the
    // setSize to work, though it does compile.
    class Canvas extends JPanel{
         Canvas(){
              setBackground(Color.white);
              Dimension canSize = new Dimension(300,300);
              setSize(canSize);
    // displays the lsit of color button choices in a small panel at bottom
    // of window
    class ColorChoices extends JPanel{
         ColorChoices() {
              setBackground(new Color(220,255,255));
              add(new OilPaint("paint",Color.blue));
              add(new OilPaint("paint",Color.red));
              add(new OilPaint("paint",Color.green));
              add(new OilPaint("paint",Color.white));
              add(new OilPaint("paint",Color.black));
    //this is the main class of the program TryPainting.java
    class TryPainting {
         public static void main(String[] args) {
              JFrame window = new JFrame();
              Toolkit toolkit = window.getToolkit();
              Dimension winSize=toolkit.getScreenSize();
              window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              window.setBounds(5,5,winSize.width/2,winSize.height/2);
              Container content = window.getContentPane();
              content.setLayout(new BorderLayout());
              content.add("North",new Canvas());
              content.add("South",new ColorChoices());
              window.setVisible(true);

    duh.. thanks man, that did the trick. i'm pretty new at this. i really appreciate the help. i got stuck thinking of the getBackground() as a function, rather than a method. this oop stuff is wacky weird fun!
    jason

  • How can I get the screen to lock on my iPhone 4, so I don't press buttons while talking?

    I just upgraded to the iPhone 4.  When I am talking on the phone, the screen doesn't lock, so I am constantly pressing buttons or hanging up on the person I'm talking to.  How can I get the screen to lock while I'm talking?  It's driving me NUTS.

    The otterbox is one of the culprits. Take the phone out of the case and see if it still happens. If so it is not the case. If the problem goes away, then you may need to make the hole slightly larger. My family has three iPhone 4's in otterboxes and none have this problem. Other users on this forum have reported success with the above methods.

  • LV 8.6: programatically pressing button only works in some VIs, not all?

    Setup is an old labview 8.6
    I'm tasked with fixing some strange old engine test bench which has a ~1E-6 measurement drift.
    The "easiest" work around fix would be to run the mechanics to a bottom end point then press the "reset" measurement button automatically.
    !!:  A "drive" vi and a "measurement" vi has to be running at the same time. The drive vi will then periodically drive the test bench to a mechanical end point and reset the measurement vi. This would get rid of the drift.
    !!:  Both vi's must be started manually and running. I cannot start one vi from the other. It messes things up. I know not why. There seems to be some strange dependency over compiled FPGA code somewhere.
    I'm no lab view wizard. It was 20 years since I touched it last.
    So digging through examples on how to press a button in one VI from another VI I found this:
    https://decibel.ni.com/content/docs/DOC-15962
    Which I built into a sub-vi and a test setup to see if I could make it work on the test bench. With some tweaking it works.
    A test "master" vi can press any button in a test "slave" vi.
    However. It is impossible to press the "reset" button in the "measurement" vi.
    Labview reports no errors, it just doesn't execute the value change event as far as I can understand.
    In fact, I can copy exactly the same code from the working "slave" vi into the "measurement" vi and it stops working. !!??
    How can code work perfectly well in one vi but not in another ?
    The "measurement" vi has some sort of compilation requirements, meaning any change to the vi takes >30min to "compile" before it can be run. Can this have something to do with why remote button pressing doesn't work?
    It also interfaces with some FPGA somewhere, can that have something to do with it ?
    I have no clue. Happy for any help here.

    Here it comes -- WARNING -- ugly code, this is my first labview in 20 years and I'm very short on time.
    press-button.vi
      the sub vi I mangle up from the example (https://decibel.ni.com/content/docs/DOC-15962)
    master.vi
      the test event sender
    slave.vi
      the test event receiver
    measurement.vi
      the real vi, where no buttons can be pressed
    In master.vi you can reconfigure the input to press-button to which vi and button to target. Right now it is set for the test slave vi (I think) to verify that it actually works as intended in the test environment.
    Hmm, seems there is a limit to 3 attachments, will post the measurement.vi in next post
    Attachments:
    press-button.vi ‏15 KB
    master.vi ‏19 KB
    slave.vi ‏29 KB

  • Problem with cheek pressing buttons while on calls

    I have never had this issues before but since my upgrade I am having problems with the 5s pressing buttons such as mute, keys,etc during calls.

    I do not have a screen protector but do have a case (Lifeproof). I had a similar Lifeproof case with my other 4s and 3 iphones and did not have this issues. Could it be the Issue with Proximity Sensor during calls?

  • New button colors hard to see

    The new light gray colors are now rather difficult to see at a glance which one is greyed out and which one is active. It is so bad that I even looked at the Universal Access System Prefs pane and bumped up the contrast but even that doesn't seem to help. Why on Earth did anyone thing this was a good idea or makes the interface more appealing in any way? Or more importantly, is there a way to bring back the old button colors?

    Most likely your home button is worn out. There is really nothing that you can do, it's just usual wear and tear. You could set up a repair through Apple. Your phone is probably out of warrany if you don't have a plan set up on your phone. You could do a repair through Apple, get a third party to repair it, or pony up and get the iPhone 5!

  • Bizarre IRR Button Colors in IE (Only!)

    When we go to any "Action" dialog from an Interactive Report Region, the button colors, e.g. Apply, Cancel etc. are dark blue with brown writing in IE only We've tested with IE 8 and 9.
    This does not occur in FF, Chrome or Safari.
    Has anyone else encountered this and does anyone know of a fix. We are demoing this next week and; it isn't just aesthetic, the color combination is actually very difficult to read.
    (Yes, I, too, wish that IE would be forever stricken from the memory of Man)
    Thanks and Here's Hoping,
    -Joe

    Joe
    Ironically a combination of IE and Jive ate a lengthy response I made some hours ago, and I wasn't able to post again at that time.
    Joe Upshaw wrote:
    Sorry that this followup is more of a CSS question and less of an APEX question.That's OK. I know more about many aspects of CSS than I do about some of APEX!
    We have a CSS style sheet that we are including as part of the application (via a change to the template).When you say this do you mean that this style sheet replaces the default APEX theme CSS or that it is applied later in the cascade to augment/override the theme?
    However, we don't have any conditional* CSS formatting. I'm unsure of the syntax. I know I could paste the <style> section thgat you provided into the HTML Header section of the page but, as this is global, we'd prefer to do it in the CSS once for the whole app.There's no conditional processing in CSS. The browser applies the last rule it understands, which for this rule is roughly like this:
    /* Older IE & IE8/9/10 */
    filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, startColorstr='#eee', endColorstr='#ddd');
    /* IE8/9/10 */
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#eee', endColorstr='#ddd')";
    /* Older Safari & Chrome */
    background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #EEE), color-stop(100%, #DDD));
    /* Safari & Chrome */
    background-image: -webkit-linear-gradient(top, #EEE,#DDD);
    /* Older Firefox */
    background-image: -moz-linear-gradient(top, #EEE,#DDD);
    /* Firefox 16 & IE10 */
    background-image: linear-gradient(top, #EEE,#DDD);So the problem with unconditionally including
    button.apexir-button {
    filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, startColorstr='#eeeeee', endColorstr='#dddddd');
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#dddddd')"
    button.apexir-button:hover {
    filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, startColorstr='#ffffff', endColorstr='#eeeeee');
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eeeeee')"
    }later in the cascade is that it will override <tt>background-image: linear-gradient(top, #EEE,#DDD)</tt> for IE10 as IE10 still supports Microsoft's proprietary <tt>filter</tt> property.
    That's why I suggested using conditional comments.
    I tried this:
    button.apexir-button {
    [if lt IE 10] filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, startColorstr='#eeeeee', endColorstr='#dddddd');
    [if lt IE 10] -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#dddddd')"
    button.apexir-button:hover {
    [if lt IE 10] filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, startColorstr='#ffffff', endColorstr='#eeeeee');
    [if lt IE 10] -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#eeeeee')"
    }and it did not solve the problem.That's not valid CSS: there's no conditional processing in CSS. We have to use the IE conditional comments in HTML.
    I also directly pasted the style tag version that you pasted above into the example at apex.oracle.com in the HTML header of the page.
    It did not solve the problem there either. Works for me. Needs to pasted in the right place after the APEX theme style sheet to effect the override.
    My recommendation would be to put the override in an external style sheet that you feed to earlier IE versions using conditional comments in each page template, which is the approach that APEX takes for IE workarounds:
    <!--[if lt IE 10]><link rel="stylesheet" href="..." type="text/css" /><![endif]-->There also another alternative: fix the errant APEX CSS at <tt>/i/themes/theme_24/css/4_1.css</tt> if the powers that be will allow it.

  • SC workflow start when pressing button held

    Hi,
    When we create a SC and then press button hold the approval workflow is started in status waiting. The problem with that is that it already has decided the approvers from the values in the SC when hold was pressed. If we then changes something in the SC that has an impact on the approval it is not considered when we press button order. The workflow continues with the first found approvers.
    I have tested to set BBP_WFL_SECURITY to 2 (restart workflow when changes), but this does not seem to have an impact before the SC has been ordered.
    Is it possible to turn of the start of the workflow until the button order is pressed? We do not want the workflow to start on hold button and then just wait for the order button to be pressed before continuing..
    All tips are appriciated!
    Regards,
    Kicki Wennerbo

    Hi,
      Which  WF are you using for the SC approval?
    BR,
    Disha.

  • I'm running Safari 6.0.5 - Mac OS 10.8.4 -- when I load my gmail the block around the DELETE and MOVE tabs are not usable - press buttons but nothing happens. ???

    I'm running Safari 6.0.5 - Mac OS 10.8.4 -- when I load my gmail the block around the DELETE and MOVE tabs are not usable - press buttons but nothing happens. ???
    I can see the block (flashes) and the buttons are no longer usable.
    I have Empted Cache but doesn't seem to help.

    From the Safari menu bar, select
    Safari ▹ Preferences ▹ Extensions
    Turn all extensions OFF and test. If the problem is resolved, turn extensions back ON and then disable them one or a few at a time until you find the culprit.
    If you wish, you may be able to salvage the malfunctioning extension by uninstalling and reinstalling it. Its settings will revert to their defaults. If the extension still causes a problem, remove it permanently or refer to its developer for support.

  • GIF image as a press button icon

    How can I apply a gif image on press button as icon, in oracle 10g forms.

    Hello,
    please do a search in the "Forum search" dialog box.
    This question has been posted hundred of times.
    Francois

  • 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

  • Press button with CL_SALV_FUNCTIONS_LIST

    I made press button on an ALV available with:
    gr_func_list->set_all(
       value  = IF_SALV_C_BOOL_SAP=>TRUE
    I want to delete just one these buttons (LOTUS).
    How can I do this with CL_SALV_FUNCITONS_LIST?

    Sample from some of my SALV code:
    data: gr_f_list  type ref to cl_salv_functions_list....
    * gui status contains Refresh button &XXL for Excel import
      gr_alv->set_screen_status( pfstatus      = 'SALV_TABLE_STANDARD'
                                 report        = sy-repid
                                 set_functions = gr_alv->c_functions_all ).
    * SALV toolbar & GUI functions
      gr_f_list = gr_alv->get_functions( ).     "Get Toolbar functions
      gr_f_list->set_all( abap_true ).          "All On
      gr_f_list->set_view_lotus( abap_false ).  "Lotus 123 off
      gr_f_list->set_view_excel( abap_false ).  "Excel in Place Off Use &XXL instead
      gr_f_list->set_graphics( abap_false ).    "Graph tool off

Maybe you are looking for