Hi,
I have my code as follows (Modified). Created action myCutAction1 similar to myCutAction and passed it to createAction() method.This method setting the accelator to keystrokes as shortcuts using item.setAccelerator(aShortCut);
The problem is.. i dnt want to show Cut1(Shift+Delete) menu item in myEditMenu JMenu in my GUI.
Whenever i am making Cut1 menuitem to not to visible in myEditMenu using setVisible(false),it is not seen myEditMenu but the thing is the keystroke (Shift+Delete) also not working. I want only the Shift+Delete operation to work though the menu item Cut1 in made invisible.
/** Action for cutting values */
private ExtendedAction myCutAction;
/** Action for cutting values */
private ExtendedAction myCutAction1;
myCutAction = createAction("Cut", myEditMenu, false,KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK));
myCutAction1 = createAction("Cut1", myEditMenu, false,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.SHIFT_MASK));
myCutAction.setEnabled(somethingSelected);
myCutAction1.setEnabled(somethingSelected);
private ExtendedAction createAction(String aName, JMenu aParentMenu, boolean aCheckBox, KeyStroke aShortCut){
return createAction(aName, aParentMenu, aCheckBox, aShortCut, false);
}
private ExtendedAction createAction(String aName, JMenu aParentMenu, boolean aCheckBox, KeyStroke aShortCut, boolean useResource){
StringTokenizer st = new StringTokenizer(aName);
String actionName = new String("");
// Remove space, \t, \n, \r, \f
while (st.hasMoreTokens()) {
actionName = actionName.concat(st.nextToken());
}
ExtendedAction action = new ExtendedAction(APPLICATION+"."+WINDOW+"."+actionName+"Action");
action.addActionListener(this);
String menuText;
if (useResource == true)
menuText = ResourceHandler.getWidgetString(APPLICATION, WINDOW, aName+"MenuItem");
else
menuText = aName;
JMenuItem item = new JMenuItem(menuText);
setName(item, actionName+"MenuItem");
if (aShortCut != null )
item.setAccelerator(aShortCut);
}
if (aParentMenu != null){
aParentMenu.add(item);
}
action.connectComponent(item);
}
myModel.getActions().addElement(action);
return action;
}
Best Regards, Santhi