This discussion is archived
0 Replies Latest reply: Apr 3, 2013 11:14 PM by KonradZuse RSS

button.setOnMouseExited() supercedes button.setOnAction() why?

KonradZuse Explorer
Currently Being Moderated
Okay so I want my button to be a gif when it's mouse is entered which it does, and return to normal which it does when exited.

That all works until I want to click the button and turn the button graphic into something else. For some reason it keeps it as the original or (mouseExited). if I don't have the mouseExited it will change the image when clicked, but it will keep the same image after entering, unless I click button to switch it to the other icon.

I tried registering eventfilters to the mouse exited and then a handler to the action(since filters register before the handlers). I also tried event.consume() and such but nothing seems to allow me to have my action dealt afterwards. It seems as if it registers "exited always."


I did however just get it to work by doing inside the mouse exited if(button.isArmed()) which worked. Is this the best way to do it though?


Edited by: KonradZuse on Apr 3, 2013 11:12 PM

It seems like it only works not when I set it as an eventFilter and Handler, not when I use setOnAction and setMouseExited, which is interesting since the filter should register first, so it shouldn't know about the arming....?
       button.setOnMouseEntered((event)
               ->{
           button.setGraphic(new ImageView(button3));
           event.consume();
                 });
                       
                button.addEventFilter(MouseEvent.MOUSE_EXITED,(event)
                        ->{
                    
                    if(button.isArmed())
                    {
                        button.setGraphic(new ImageView(button2));
                    }
                    else
                    {
                        button.setGraphic(new ImageView(button1));
                    }
                        event.consume();
                });
          
                

button.addEventHandler(MouseEvent.MOUSE_PRESSED, (event)
        ->{ 
            button.setGraphic(new ImageView(button2));
            imageV.setImage(body2);
            button.setMouseTransparent(true);
            timer();
            event.consume();
            
          });
                
Edited by: KonradZuse on Apr 3, 2013 11:14 PM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points