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


Java JMenuItem.addPropertyChangeListener方法代碼示例

本文整理匯總了Java中javax.swing.JMenuItem.addPropertyChangeListener方法的典型用法代碼示例。如果您正苦於以下問題:Java JMenuItem.addPropertyChangeListener方法的具體用法?Java JMenuItem.addPropertyChangeListener怎麽用?Java JMenuItem.addPropertyChangeListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JMenuItem的用法示例。


在下文中一共展示了JMenuItem.addPropertyChangeListener方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addOptionListener

import javax.swing.JMenuItem; //導入方法依賴的package包/類
/**
 * Adds a refresh listener to the menu item of an option
 * with a given name.
 * @see #getRefreshListener
 */
public void addOptionListener(String option) {
    JMenuItem optionItem = getOptions().getItem(option);
    if (optionItem == null) {
        throw new IllegalArgumentException(String.format("Unknown option: %s", option));
    }
    RefreshListener listener = getRefreshListener(option);
    if (listener != null) {
        optionItem.addItemListener(listener);
        optionItem.addPropertyChangeListener(listener);
        this.optionListeners.add(Pair.newPair(optionItem, listener));
    }
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:18,代碼來源:JGraph.java

示例2: doTestRefreshAfterBeingHidden

import javax.swing.JMenuItem; //導入方法依賴的package包/類
private void doTestRefreshAfterBeingHidden(boolean clone, boolean menu) throws IOException {
    InstanceContent ic = new InstanceContent();
    Lookup context = new AbstractLookup(ic);
    
    
    Action instance;
    if (clone) {
        Action a = create(Lookup.EMPTY);
        instance = ((ContextAwareAction)a).createContextAwareInstance(context);
    } else {
        instance = create(context);
    }
    
    if (!(instance instanceof Presenter.Popup)) {
        // cannot test, skipping
        return;
    }
    
    
    CharSequence log1 = Log.enable("org.netbeans.modules.project.ui.actions", Level.FINER);
    assertFalse("Disabled", instance.isEnabled());
    if (!log1.toString().contains("Refreshing")) {
        fail("Should be refreshing: " + log1);
    }
    
    JMenuItem item = item(instance, menu);
    JMenu jmenu = new JMenu();
    jmenu.addNotify();
    assertTrue("Peer created", jmenu.isDisplayable());
    jmenu.getPopupMenu().addNotify();
    assertTrue("Peer for popup", jmenu.getPopupMenu().isDisplayable());
    
    item.addPropertyChangeListener(this);
    jmenu.add(item);
    assertEquals("anncessor properly changes, this means the actions framework is activated", 1, ancEvent);
    
    
    assertFalse("Not enabled", item.isEnabled());
    FileObject pfo = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "yaya");
    FileObject pf2 = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "blabla");
    MockServices.setServices(TestSupport.TestProjectFactory.class);
    Project p = ProjectManager.getDefault().findProject(pfo);
    Project p2 = ProjectManager.getDefault().findProject(pf2);
    if (p instanceof TestSupport.TestProject) {
        enhanceProject((TestSupport.TestProject)p);
    }
    if (p2 instanceof TestSupport.TestProject) {
        enhanceProject((TestSupport.TestProject)p2);
    }
    
    assertNotNull("Project found", p);
    assertNotNull("Project2 found", p2);
    OpenProjects.getDefault().open(new Project[] { p }, false);
    ic.add(p);
    assertTrue("enabled", item.isEnabled());
    assertEquals("One change", 1, change);

    if (menu) {
        item.removeNotify();
        CharSequence log2 = Log.enable("org.netbeans.modules.project.ui.actions", Level.FINER);
        ic.remove(p);
        ic.add(p2);
        if (log2.length() > 0) {
            fail("Nothing shall happen:\n" + log2);
        }
    } // irrelevant for popups
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:68,代碼來源:LookupSensitiveActionBase.java


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