本文整理汇总了Java中javax.swing.JMenu.getMenuComponent方法的典型用法代码示例。如果您正苦于以下问题:Java JMenu.getMenuComponent方法的具体用法?Java JMenu.getMenuComponent怎么用?Java JMenu.getMenuComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenu
的用法示例。
在下文中一共展示了JMenu.getMenuComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setActionMenuBar
import javax.swing.JMenu; //导入方法依赖的package包/类
public void setActionMenuBar(String menuItem, Action action) {
for (int i = 0; i < mMenuBar.getMenuCount(); i++) {
JMenu menu = mMenuBar.getMenu(i);
for (int j = 0; j < menu.getMenuComponentCount(); j++) {
Component component = menu.getMenuComponent(j);
if (component instanceof JMenuItem) {
JMenuItem item = (JMenuItem) component;
String description = (String) item.getAction().getValue(Action.SHORT_DESCRIPTION);
if (description.equals(menuItem)) {
item.setAction(action);
item.setText(menuItem);
break;
}
}
}
}
}
示例2: enableAll
import javax.swing.JMenu; //导入方法依赖的package包/类
/**
* Convenience method that recursively enables every JMenu and JMenuItem
* inside "menu".
*
* @param menu - the menu to start the recursive search
*/
public static void enableAll(JMenu menu) {
for (int i = 0; i < menu.getMenuComponentCount(); i++) {
Component x = menu.getMenuComponent(i);
if (x instanceof JMenuItem)
((JMenuItem) x).setEnabled(true);
else if (x instanceof JMenu)
enableAll((JMenu) x);
}
}
示例3: setMnemonics
import javax.swing.JMenu; //导入方法依赖的package包/类
private static void setMnemonics(final JMenuItem item) {
if (item instanceof JMenu) {
final JMenu menu = (JMenu) item;
final int c = menu.getMenuComponentCount();
final ArrayList<JMenuItem> list = new ArrayList<JMenuItem>(c);
for (int i = 0; i < c; i++) {
final Component co = menu.getMenuComponent(i);
if (co instanceof JMenuItem)
list.add((JMenuItem) co);
}
if (list.size() > 0)
setMnemonics(list);
}
}
示例4: enableAll
import javax.swing.JMenu; //导入方法依赖的package包/类
/** Convenience method that recursively enables every JMenu and JMenuItem inside "menu".
* @param menu - the menu to start the recursive search
*/
public static void enableAll (JMenu menu) {
for(int i = 0; i < menu.getMenuComponentCount(); i++) {
Component x = menu.getMenuComponent(i);
if (x instanceof JMenuItem) ((JMenuItem)x).setEnabled(true); else if (x instanceof JMenu) enableAll((JMenu)x);
}
}
示例5: menuDeselected
import javax.swing.JMenu; //导入方法依赖的package包/类
public void menuDeselected(MenuEvent e) {
JMenu wm = (JMenu) e.getSource();
// Cleans Windows if not visible
if(wm.getText().matches("Windows") || wm.getText().matches("Window")) {
wm.removeAll();
System.gc();
}
/* When user first imports menu item the background is set to another color to catch user attention.
* After user interaction will set the background color back.
*/
if(wm.getText().matches("My Layer Sessions")) {
JMenu selectSessionMenu = (JMenu) wm;
try {
JMenuItem selectSessionMenuChild = (JMenuItem) selectSessionMenu.getMenuComponent(0);
Color currentColor = selectSessionMenu.getBackground();
Color defaultColor = selectSessionMenuChild.getBackground();
if(currentColor.getRed() + currentColor.getGreen() + currentColor.getBlue() == 586) {
selectSessionMenu.setBackground(defaultColor);
selectSessionMenu.revalidate();
}
} catch (Exception ex) {
//don't do anything if menu component and cannot be cast as a JMenuItem
//(eg if it is a separator bar)
}
}
}