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