How to remove Hover from menu items and buttons?

Asked

Viewed 217 times

3

I think my question is very objective: how to remove the "Hover effect of menu items and buttons? Here is a screenshot of the Hover effect I intend to remove (button and menu items):

inserir a descrição da imagem aqui

1 answer

5


That depends a lot on the Look and Feel(LAF) that is being used in the application, because it is usually he who defines this type of characteristic 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"));

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

inserir a descrição da imagem aqui

It is also possible to create the UI for the JMenuItem manually, but particularly I find it quite complex to do, and it is possible to change with only two lines.

If you use the LAF of the system where the application is running, or use another such as the Nimbus, there is no choice but to do what I mentioned in the previous paragraph, as the suggested amendments will not work for these two cases.


And to JButtons, you can use the method setRolloverEnabled(), but 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.