本文整理匯總了Java中javax.swing.JMenuItem.getAction方法的典型用法代碼示例。如果您正苦於以下問題:Java JMenuItem.getAction方法的具體用法?Java JMenuItem.getAction怎麽用?Java JMenuItem.getAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.getAction方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setMenu
import javax.swing.JMenuItem; //導入方法依賴的package包/類
/** Sets the state of JMenuItem*/
protected @Override void setMenu(){
ActionMap am = getContextActionMap();
Action action = null;
if (am != null) {
action = am.get(getActionName());
}
JMenuItem presenter = getMenuPresenter();
Action presenterAction = presenter.getAction();
if (presenterAction == null){
presenter.setAction(this);
presenter.setToolTipText(null); /* bugfix #62872 */
menuInitialized = false;
}
else {
if (!this.equals(presenterAction)){
presenter.setAction(this);
presenter.setToolTipText(null); /* bugfix #62872 */
menuInitialized = false;
}
}
if (!menuInitialized){
Mnemonics.setLocalizedText(presenter, getMenuItemText());
menuInitialized = true;
}
presenter.setEnabled(action != null);
JTextComponent comp = Utilities.getFocusedComponent();
if (comp != null && comp instanceof JEditorPane){
addAccelerators(this, presenter, comp);
} else {
presenter.setAccelerator(getDefaultAccelerator());
}
}
示例2: removeMenuItem
import javax.swing.JMenuItem; //導入方法依賴的package包/類
protected void removeMenuItem(JMenuItem itemToRemove) {
Action a = itemToRemove.getAction();
// start by searching this menu
XJMenu menuToUse = this;
int firstIndex = firstPluginItem;
// keep track of the parent menu
XJMenu parentMenu = null;
// if the action has a menu path set, navigate the path to find the
// right menu.
String[] menuPath = (String[])a.getValue(GateConstants.MENU_PATH_KEY);
if(menuPath != null) {
PATH_ELEMENT: for(String pathElement : menuPath) {
int i;
for(i = firstIndex; i < menuToUse.getItemCount(); i++) {
JMenuItem item = menuToUse.getItem(i);
if(item instanceof XJMenu && item.getText().equals(pathElement)) {
// found the menu for this path element, move on to the next one
firstIndex = 0;
parentMenu = menuToUse;
menuToUse = (XJMenu)item;
continue PATH_ELEMENT;
}
}
// we've reached the end of a menu without finding the sub-menu
// we were looking for. This shouldn't happen, but if it does then
// we can ignore it as if there's no menu to remove the thing from
// then there's nothing to remove either.
return;
}
}
// we have a menu to remove the item from: remove it
menuToUse.remove(itemToRemove);
if(menuToUse.getItemCount() == 0 && parentMenu != null) {
// sub-menu is empty, remove it from parent
parentMenu.remove(menuToUse);
}
}
示例3: installAcceleratorPreview
import javax.swing.JMenuItem; //導入方法依賴的package包/類
private static void installAcceleratorPreview(JMenuItem item) {
if(item instanceof JMenu) return;
//detect accelerator key
boolean already_has_accel = false;
if(item.getAccelerator() != null) already_has_accel = true;
if(item.getAction() != null && item.getAction().getValue(Action.ACCELERATOR_KEY) != null) already_has_accel = true;
boolean already_has_accel_border = false;
if(item.getBorder() == accel_border) {
already_has_accel_border = true;
//uninstall if needed
if(already_has_accel) {
item.setBorder(null);
return;
}
}
if(item.getBorder() instanceof CompoundBorder) {
CompoundBorder comp = (CompoundBorder)item.getBorder();
if(comp.getInsideBorder() == accel_border) {
already_has_accel_border = true;
//uninstall if needed
if(already_has_accel) {
item.setBorder(comp.getOutsideBorder());
return;
}
}
}
if(already_has_accel_border) return;
if(already_has_accel) return;
if(item.getBorder() == null) {
item.setBorder(accel_border);
return;
}
item.setBorder(BorderFactory.createCompoundBorder(
item.getBorder(),accel_border));
}