本文整理汇总了Java中javax.swing.JMenuItem.getAccelerator方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.getAccelerator方法的具体用法?Java JMenuItem.getAccelerator怎么用?Java JMenuItem.getAccelerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.getAccelerator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assignAccelerator
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static void assignAccelerator(Keymap km, Action action, JMenuItem item) {
if (item.getAccelerator() == null){
KeyStroke ks = (KeyStroke)action.getValue(Action.ACCELERATOR_KEY);
if (ks!=null) {
item.setMnemonic(ks.getKeyCode());
} else {
// Try to get the accelerator from keymap
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(action);
if (keys != null && keys.length > 0) {
item.setMnemonic(keys[0].getKeyCode());
}
}
}
}
}
示例2: addAccelerators
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/** Adds accelerators to given JMenuItem taken from the action */
protected static void addAccelerators(Action a, JMenuItem item, JTextComponent target){
if (target == null || a==null || item==null) return;
// get accelerators from kitAction
Action kitAction = getActionByName((String)a.getValue(Action.NAME));
if (kitAction!=null) a = kitAction;
// Try to get the accelerator, TopComponent action could be obsoleted
Keymap km = target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
KeyStroke itemAccelerator = item.getAccelerator();
if (keys != null && keys.length > 0) {
if (itemAccelerator==null || !itemAccelerator.equals(keys[0])){
item.setAccelerator(keys[0]);
}
}else{
if (itemAccelerator!=null && kitAction!=null){
item.setAccelerator(null);
}
}
}
}
示例3: NbMenuItem
import javax.swing.JMenuItem; //导入方法依赖的package包/类
/**
* @param it
* @return instance of NbMenuItem constructed from parameter it */
public NbMenuItem(JMenuItem it) {
setName(it.getText());//getLabel();
this.accelerator = (it.getAccelerator() == null) ? null : it.getAccelerator().toString();
this.mnemo = (char) it.getMnemonic();
// System.out.println("NbMenuItem ["+name+"] - mnemo: ["+it.getMnemonic()+"]"); why are the mnemonic always in capital?
this.enabled = it.isEnabled();
this.checkbox = it instanceof JCheckBoxMenuItem;
this.radiobutton = it instanceof JRadioButtonMenuItem;
this.checked = it.isSelected();
}
示例4: getAcceleratorWidth
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static int getAcceleratorWidth(JMenuItem item) {
if(item instanceof JMenu) return 0;
if(item.getAccelerator() != null) return 50;
return MenuEditLayer.ACCEL_PREVIEW_WIDTH; // gutter space that we can click on to add an accelerator
}
示例5: 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));
}
示例6: NbMenu
import javax.swing.JMenuItem; //导入方法依赖的package包/类
NbMenu(JMenuItem menu, List<NbMenu> submenu) {
name = menu.getText();//getLabel();
accelerator = (menu.getAccelerator() == null) ? null : menu.getAccelerator().toString();
mnemo = menu.getMnemonic();
this.submenu = submenu;
}