本文整理汇总了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));
}