Java JMenuBar pushMenu(JMenuBar jmenubar, String[][] menus)

Here you can find the source of pushMenu(JMenuBar jmenubar, String[][] menus)

Description

push Menu

License

LGPL

Declaration

public static void pushMenu(JMenuBar jmenubar, String[][] menus) 

Method Source Code

//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);
            }
        });
    }
}

Related

  1. getJMenuByName(JMenuBar bar, String name)
  2. getMenu(JMenuBar loMenuBar, String psComando)
  3. getMenuItem(JMenuBar menu, String text)
  4. launch(String title, JComponent component, JMenuBar menuBar)
  5. menu(String text, char mnemonic, JMenuBar menuBar)
  6. selectMenuItem(JMenuBar menuBar, Action action, boolean selected)
  7. selectSaveFile(JMenuBar menuBar)