Java Code Examples for javax.swing.JMenu#isTopLevelMenu()

The following examples show how to use javax.swing.JMenu#isTopLevelMenu() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MenuUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
			} 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);
}
 
Example 2
Source File: BEMenuUI.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public void mouseEntered(MouseEvent evt) {
	super.mouseEntered(evt);

	JMenu menu = (JMenu)evt.getSource();
	if (hotTrackingOn && menu.isTopLevelMenu() && menu.isRolloverEnabled()) {
		menu.getModel().setRollover(true);
		menuItem.repaint();
	}
}
 
Example 3
Source File: BEMenuUI.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
/**
     * Method which renders the text of the current menu item.
     * <p>
     * @param g Graphics context
     * @param menuItem Current menu item to render
     * @param textRect Bounding rectangle to render the text.
     * @param text String to render
     * @since 1.4
     */
    protected void paintText(Graphics g, JMenuItem menuItem,
    		Rectangle textRect, String text) 
    {
    	//================= commet by Jack Jiang START
//    	if (WindowsMenuItemUI.isVistaPainting()) {
//    		WindowsMenuItemUI.paintText(accessor, g, menuItem, textRect, text);
//    		return;
//    	}
    	//================= commet by Jack Jiang END
    	JMenu menu = (JMenu)menuItem;
    	ButtonModel model = menuItem.getModel();
    	Color oldColor = g.getColor();

    	// Only paint rollover if no other menu on menubar is selected
    	boolean paintRollover = model.isRollover();
    	if (paintRollover && menu.isTopLevelMenu()) {
    		MenuElement[] menus = ((JMenuBar)menu.getParent()).getSubElements();
    		for (int i = 0; i < menus.length; i++) {
    			if (((JMenuItem)menus[i]).isSelected()) {
    				paintRollover = false;
    				break;
    			}
    		}
    	}

    	if ((model.isSelected() && 
    							(
//    							WindowsLookAndFeel.isClassicWindows() ||
    							!menu.isTopLevelMenu())) 
    			||
    			(
//    					BEXPStyle.getXP() != null && 
    					(paintRollover ||model.isArmed() ||model.isSelected())
    			)
    	) 
    	{
    		g.setColor(selectionForeground); // Uses protected field.
    	}

    	//================= add by Jack Jiang START
    	//特殊处理顶级菜单项(就是直接放在JMenuBar上的那一层),使之在被选中或rover等状态时保持黑色(或其它颜色)
    	//,目的是为了配合整个菜单项的L&F效果,并没有过多的用途,此颜色可提取作为UIManager的自定义属性哦
    	if(menu.isTopLevelMenu())
    		g.setColor(new Color(35,35,35));//用MaxOS X的经典黑
    	//================= add by Jack Jiang END
    	
//    	WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
    	WinUtils.paintText(g, menuItem, textRect, text, 0);
    	
    	g.setColor(oldColor);
    }