本文整理汇总了Java中javax.swing.JMenuItem.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.getParent方法的具体用法?Java JMenuItem.getParent怎么用?Java JMenuItem.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.getParent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildMenuElementArray
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private String buildMenuElementArray(JMenuItem leaf) {
Vector<JMenuItem> elements = new Vector<JMenuItem>();
elements.insertElementAt(leaf, 0);
Component current = leaf.getParent();
while (current != null) {
if (current instanceof JPopupMenu) {
JPopupMenu pop = (JPopupMenu) current;
current = pop.getInvoker();
} else if (current instanceof JMenu) {
JMenu menu = (JMenu) current;
elements.insertElementAt(menu, 0);
current = menu.getParent();
} else if (current instanceof JMenuBar) {
break;
} else {
current = current.getParent();
}
}
mainMenu = elements.get(0);
JMenuItem parent = null;
StringBuilder sb = new StringBuilder();
RComponentFactory finder = new RComponentFactory(omapConfig);
for (JMenuItem jMenuItem : elements) {
RComponent rComponent = finder.findRComponent(jMenuItem, null, recorder);
recorder.recordMenuItem(rComponent);
String text = JMenuItemJavaElement.getText(JMenuItemJavaElement.getItemText(jMenuItem), jMenuItem,
parent == null ? new Component[0] : ((JMenu) parent).getMenuComponents());
parent = jMenuItem;
sb.append(text).append(">>");
}
sb.setLength(sb.length() - 2);
return sb.toString();
}
示例2: hasRadioOrCheckSibling
import javax.swing.JMenuItem; //导入方法依赖的package包/类
private static boolean hasRadioOrCheckSibling(JMenuItem item) {
if(item.getParent() == null) return false;
for(Component c : item.getParent().getComponents()) {
if(c instanceof JRadioButtonMenuItem) return true;
if(c instanceof JCheckBoxMenuItem) return true;
}
return false;
}
示例3: paintBackground
import javax.swing.JMenuItem; //导入方法依赖的package包/类
@Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
JMenu menu = (JMenu) menuItem;
ButtonModel buttonmodel = menu.getModel();
int w = menu.getWidth();
int h = menu.getHeight();
Color oldColor = g.getColor();
if (!menu.isContentAreaFilled() || !menu.isOpaque()) {
// do nothing
} else {
if (menu.isTopLevelMenu()) {
if (buttonmodel.isSelected()) {
CachedPainter.drawMenuBackground(menuItem, g, 0, 0, w, h);
} else if (buttonmodel.isRollover() && buttonmodel.isEnabled()) {
g.setColor(Colors.MENUBAR_BACKGROUND_HIGHLIGHT);
g.fillRect(0, 0, w, h);
g.setColor(Colors.MENU_ITEM_BACKGROUND);
g.drawRect(0, 0, w - 1, h - 1);
} else {
if (menuItem.getParent() instanceof JMenuBar) {
((MenuBarUI) ((JMenuBar) menuItem.getParent()).getUI()).update(g, menuItem);
}
}
} else {
if (!menuItem.getModel().isSelected()) {
RapidLookTools.drawMenuItemFading(menuItem, g);
} else {
RapidLookTools.drawMenuItemBackground(g, menuItem);
}
}
}
g.setColor(oldColor);
}