本文整理匯總了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)
}
}
}