3
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:
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.
Okay, I get it, thank you so much for your help.
– Rafael Souza Calearo