I'm learning java with Swing. I have a problem with setAccelerator for menu. My code:
closeItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_W, ActionEvent.CTRL_MASK));
closeOtherItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_W, ActionEvent.CTRL_MASK&ActionEvent.SHIFT_MASK));
I want when I press Ctrl+W, my JTabbedPane will close selectedTab, and when press Ctrl+Shift+W my JtabbedPane will close all ignore selectedTab. But only action Ctrl+W was detected, although when I click on closeOtherItem my program will run normally.
Try or'ing the modifers instead of and'ing and use
InputEvent.CTRL_DOWN_MASK
andInputEvent.SHIFT_DOWN_MASK
instead...