本文整理匯總了Java中javax.swing.JCheckBoxMenuItem.setEnabled方法的典型用法代碼示例。如果您正苦於以下問題:Java JCheckBoxMenuItem.setEnabled方法的具體用法?Java JCheckBoxMenuItem.setEnabled怎麽用?Java JCheckBoxMenuItem.setEnabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JCheckBoxMenuItem
的用法示例。
在下文中一共展示了JCheckBoxMenuItem.setEnabled方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addCheckbox
import javax.swing.JCheckBoxMenuItem; //導入方法依賴的package包/類
/**
* Adds a checkbox item with a given name to the options, and returns the
* associated (fresh) menu item.
* @param name the name of the checkbox menu item to add
* @return the added {@link javax.swing.JCheckBoxMenuItem}
*/
private final JCheckBoxMenuItem addCheckbox(final String name) {
JCheckBoxMenuItem result = new JCheckBoxMenuItem(name);
boolean selected = userPrefs.getBoolean(name, boolOptionDefaults.get(name));
boolean enabled = isEnabled(name);
result.setSelected(selected & enabled);
this.itemMap.put(name, result);
if (enabled) {
result.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
userPrefs.putBoolean(name, e.getStateChange() == ItemEvent.SELECTED);
}
});
} else {
result.setEnabled(false);
}
return result;
}
示例2: fill
import javax.swing.JCheckBoxMenuItem; //導入方法依賴的package包/類
private void fill() {
removeAll();
DockableState[] dockables = dockingContext.getDesktopList().get(0).getDockables();
List<DockableState> sorted = new LinkedList<>();
sorted.addAll(Arrays.asList(dockables));
Collections.sort(sorted, new Comparator<DockableState>() {
@Override
public int compare(DockableState o1, DockableState o2) {
return o1.getDockable().getDockKey().getName().compareTo(o2.getDockable().getDockKey().getName());
}
});
for (final DockableState state : sorted) {
if (state.getDockable() instanceof DummyDockable) {
continue;
}
DockKey dockKey = state.getDockable().getDockKey();
boolean cont = false;
for (String prefix : HIDE_IN_DOCKABLE_MENU_PREFIX_REGISTRY) {
if (dockKey.getKey().startsWith(prefix)) {
cont = true;
break;
}
}
if (cont) {
continue;
}
String description = null;
if (dockKey instanceof ResourceDockKey) {
description = ((ResourceDockKey) dockKey).getShortDescription();
}
description = description != null ? description : "";
String text = dockKey.getName();
if (SystemInfoUtilities.getOperatingSystem() != OperatingSystem.OSX) {
// OS X cannot use html in menus so only do it for other OS
text = "<html><p style='margin-left:5'><b>" + dockKey.getName() + "</b><br/>" + description + "</p></html>";
}
JCheckBoxMenuItem item = new JCheckBoxMenuItem(text, dockKey.getIcon());
item.setSelected(!state.isClosed());
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (state.isClosed()) {
dockingContext.getDesktopList().get(0).addDockable(state.getDockable());
} else {
dockingContext.getDesktopList().get(0).close(state.getDockable());
}
}
});
// special handling for results overview dockable in Results perspective
// this dockable is not allowed to be closed so we disable this item while in said
// perspective
if (RapidMinerGUI.getMainFrame().getPerspectiveController().getModel().getSelectedPerspective().getName()
.equals(PerspectiveModel.RESULT)
&& ResultDisplay.RESULT_DOCK_KEY.equals(state.getDockable().getDockKey().getKey())) {
item.setEnabled(false);
}
add(item);
}
}