Here you can find the source of pushMenu(JMenuBar jmenubar, String[][] menus)
public static void pushMenu(JMenuBar jmenubar, String[][] menus)
//package com.java2s; //License from project: LGPL import java.awt.Color; import java.awt.Component; import java.awt.event.MouseEvent; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.event.MouseInputAdapter; public class Main { public static void pushMenu(JMenuBar jmenubar, String[][] menus) { Color MENU_YELLOW = new Color(236, 233, 216); Color MENU_BLUE = new Color(49, 106, 197); jmenubar.setBackground(MENU_YELLOW); for (int i = 0; i < menus.length; i++) { final JMenu jmenu = new JMenu(menus[i][0]); addHoverEffect4MenuAbout(jmenu, MENU_BLUE, Color.WHITE, MENU_YELLOW, Color.BLACK); jmenu.setBackground(MENU_YELLOW); jmenubar.add(jmenu);// www . ja va2 s . c o m for (int j = 1; j < menus[i].length; j++) { final JMenuItem jmenuitem = new JMenuItem(menus[i][j]); addHoverEffect4MenuAbout(jmenuitem, MENU_BLUE, Color.WHITE, Color.WHITE, Color.BLACK); jmenu.add(jmenuitem); } } } private static void addHoverEffect4MenuAbout(final Component component, final Color overbgcolor, final Color overfgcolor, final Color outbgcolor, final Color outfgcolor) { component.addMouseListener(new MouseInputAdapter() { @Override public void mouseEntered(MouseEvent e) { component.setBackground(overbgcolor); component.setForeground(overfgcolor); } @Override public void mouseExited(MouseEvent e) { component.setBackground(outbgcolor); component.setForeground(outfgcolor); } @Override public void mousePressed(MouseEvent e) { component.setBackground(overbgcolor); component.setForeground(overfgcolor); } @Override public void mouseReleased(MouseEvent e) { component.setBackground(outbgcolor); component.setForeground(outfgcolor); } }); } }