當前位置: 首頁>>代碼示例>>Java>>正文


Java JMenuItem.getAccelerator方法代碼示例

本文整理匯總了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());
                }
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:NbEditorKit.java

示例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);
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:MainMenuAction.java

示例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();
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:NbMenuItem.java

示例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
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:6,代碼來源:DropTargetLayer.java

示例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));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:44,代碼來源:MenuEditLayer.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:7,代碼來源:MenuChecker.java


注:本文中的javax.swing.JMenuItem.getAccelerator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。