In Java, by using non-default system look and feel we will have different keymap.
For example I'm using Mac OS X and use Substance look and feel (non-default system look and feel). The effect is I'm loosing my "meta" key for select all on text component In mac os x should be "meta + a", but using Substance we have to use "ctrl + a" (and a lot more such as "next word", "prev word", "end line, "begin line", etc) So we didn't have the mac os x feel by using non-default system look and feel (Substance look and feel).
Is there a way to use non-default system look and feel but use system (native) keymap?
The work around
A less elegant solution, you could try adding a key listener to override the default "ctrl + a" behavior by implementing a keyPressed method (please note that the following sample does not disallow "ctrl + a" just adds support for "meta + a"):
@Override
public void keyPressed(final KeyEvent e) {
// Get the default toolkit shortcut mask ("meta" for OSX).
int keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
// You could also check modifiers against KeyEvent.META_MASK...
if (e.getModifiers() == keyMask && e.getKeyCode() == KeyEvent.VK_A) {
// Select everything (assumes member of child text component class).
this.selectAll();
// We handled this keystroke, 'a' will be ignored by underlying text component.
e.consume();
}
}
A better alternative would be to use inputMaps (see comment by uudashr below).
Thoughts on the root cause
Unfortunately, as the class name suggests the look and feel (or LAF) is a combination of appearance i.e. look, as well as "system behavior", i.e. feel. If you dig around the substance source, the SubstanceLookAndFeel overrides the BasicLookAndFeel that ships with swing. It looks as though it is within the BasicLookAndFeel the offending behavior is set in initComponentDefaults. You should be able to get the UIDefaults from the LAF by calling getDefaults().
Problems from here are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With