How to remove hover from menu items and buttons?

3

I think my question is quite objective: how to remove the hover effect from menu items and buttons? Here is an image of the hover effect that I want to remove (button and menu items):

    
asked by anonymous 06.11.2017 / 20:23

1 answer

5

This depends a lot on the Look and Feel (LAF) that is being used in the application, since it is usually the one that defines this type of feature of the components.

If you have not modified what java defines by default (which is called "Metal"), the simplest way would be to change the specific properties of this LAF:

UIManager.put("MenuItem.selectionBackground", UIManager.getColor("MenuItem.background"));
UIManager.put("MenuItem.selectionForeground", UIManager.getColor("MenuItem.foreground"));

Actually, this is a "workaround" where I set the same background colors and foreground colors for the colors that would be applied when JMenuItem is selected. This causes the effect below:

ItisalsopossibletocreatetheUIforJMenuItemmanually,butIpersonallyfinditquitecomplextodo,anditispossibletochangewithonlytwolines.

IfyouusethesystemLAFwheretheapplicationisrunning,oruseanotheronesuchas < Nimbus , there you have no choice but to do what I quoted in the previous paragraph, as the suggested changes will not work for these two cases.

And for JButtons , you can use the setRolloverEnabled() , but it will end up falling into the same problem, because depending on the LAF used, it can simply ignore this command and not remove the effect.

    
07.11.2017 / 01:46