Example usage for javax.swing JMenu JMenu

List of usage examples for javax.swing JMenu JMenu

Introduction

In this page you can find the example usage for javax.swing JMenu JMenu.

Prototype

public JMenu() 

Source Link

Document

Constructs a new JMenu with no text.

Usage

From source file:GetIt.java

public static void main(String args[]) throws Exception {
    JMenu it = new JMenu();
    String classID = it.getUIClassID();
    System.out.println(classID);//  w w  w  .  j  a  v a 2  s  .  c  om
    String className = (String) UIManager.get(classID);
    System.out.println(className);
    Class.forName(className);
    System.out.println(System.getProperty("swing.defaultlaf"));
    System.out.println(System.getProperty("swing.auxiliarylaf"));
    System.out.println(System.getProperty("swing.plaf.multiplexinglaf"));
    System.out.println(System.getProperty("swing.installedlafs"));
}

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu();
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);//from  w ww  . j  a v  a  2 s .c  om

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
    fileMenu.add(newMenuItem);

    JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive");
    caseMenuItem.setMnemonic(KeyEvent.VK_C);
    fileMenu.add(caseMenuItem);

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Creates a {@link JMenu} from the given list and action map.
 * /*w w  w  .  j av a2s .  c  o m*/
 * @param actionMap
 * @param list
 * @return
 */
public static JMenu createMenu(ActionMap actionMap, List<?> list) {
    // The first item will be the action for the JMenu
    final Action titleAction = actionMap.get(list.get(0));
    if (titleAction == null) {
        return null;
    }
    final JMenu menu = new JMenu();
    menu.setAction(titleAction);

    // The rest of the items represent the menu items.
    for (Object element : list.subList(1, list.size())) {
        if (element == null) {
            menu.addSeparator();
        } else if (element instanceof List<?>) {
            JMenu newMenu = createMenu(actionMap, (List<?>) element);
            if (newMenu != null) {
                menu.add(newMenu);
            }
        } else if (element.getClass().isArray()) {
            JMenu newMenu = createMenu(actionMap, (Object[]) element);
            if (newMenu != null) {
                menu.add(newMenu);
            }
        } else {
            final Action action = actionMap.get(element);
            if (action == null) {
                continue;
            } else {
                menu.add(createMenuItem(action));
            }
        }
    }
    return menu;
}

From source file:Main.java

/**
 * Creates a copy of this menu item, whose contents update automatically
 * whenever the original menu item changes.
 *//*from   w ww.  j a v  a 2s  . c  o  m*/
public static JMenuItem cloneMenuItem(final JMenuItem item) {
    if (item == null)
        return null;
    JMenuItem jmi;
    if (item instanceof JMenu) {
        final JMenu menu = (JMenu) item;
        final JMenu jm = new JMenu();
        final int count = menu.getItemCount();
        for (int i = 0; i < count; i++) {
            final JMenuItem ijmi = cloneMenuItem(menu.getItem(i));
            if (ijmi == null)
                jm.addSeparator();
            else
                jm.add(ijmi);
        }
        jmi = jm;
    } else
        jmi = new JMenuItem();
    final ActionListener[] l = item.getActionListeners();
    for (int i = 0; i < l.length; i++)
        jmi.addActionListener(l[i]);
    jmi.setActionCommand(item.getActionCommand());
    syncMenuItem(item, jmi);
    linkMenuItem(item, jmi);
    return jmi;
}

From source file:MainClass.java

public MainClass() {
    JFrame frame = new JFrame();
    JTextPane textPane = new JTextPane();
    JScrollPane scrollPane = new JScrollPane(textPane);

    JPanel north = new JPanel();

    JMenuBar menu = new JMenuBar();
    JMenu styleMenu = new JMenu();
    styleMenu.setText("Style");

    Action boldAction = new BoldAction();
    boldAction.putValue(Action.NAME, "Bold");
    styleMenu.add(boldAction);//from  ww w.  ja  v a 2 s  .  c  o m

    Action italicAction = new ItalicAction();
    italicAction.putValue(Action.NAME, "Italic");
    styleMenu.add(italicAction);

    Action foregroundAction = new ForegroundAction();
    foregroundAction.putValue(Action.NAME, "Color");
    styleMenu.add(foregroundAction);

    Action formatTextAction = new FontAndSizeAction();
    formatTextAction.putValue(Action.NAME, "Font and Size");
    styleMenu.add(formatTextAction);

    menu.add(styleMenu);

    north.add(menu);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(north, BorderLayout.NORTH);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(800, 500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:cz.lidinsky.editor.Menu.java

protected JMenuItem loadMenuItem(Properties settings, String key) {
    try {/*  w w  w . j a v a 2  s.  c  om*/
        String temp = settings.getProperty(key + "_menu_items");
        JMenuItem menuItem;
        if (temp != null) {
            JMenu menu = new JMenu();
            String menuItems[] = temp.split(" ");
            for (String item : menuItems) {
                if (item.equals("|")) {
                    menu.add(new JSeparator());
                } else {
                    menu.add(loadMenuItem(settings, item));
                }
            }
            menuItem = menu;
        } else {
            menuItem = new JMenuItem();
        }
        // set the menu item label
        setLabel(menuItem, settings.getProperty(key + "_menu_label"));
        // action
        String actionKey = settings.getProperty(key + "_menu_action");
        if (actionKey != null) {
            menuItem.setAction(Action.getAction(settings, actionKey));
        }
        return menuItem;
    } catch (Exception e) {
        // TODO:
        throw new AssertionError();
    }
}

From source file:MainClass.java

public MainClass() {
    JFrame frame = new JFrame();
    textPane = new JTextPane();
    JScrollPane scrollPane = new JScrollPane(textPane);

    JPanel north = new JPanel();
    JButton print = new JButton("Print");
    print.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            paintToPDF(textPane);//from   w  ww .  java2s  .co m
        }
    });
    JMenuBar menu = new JMenuBar();
    JMenu styleMenu = new JMenu();
    styleMenu.setText("Style");

    Action boldAction = new BoldAction();
    boldAction.putValue(Action.NAME, "Bold");
    styleMenu.add(boldAction);

    Action italicAction = new ItalicAction();
    italicAction.putValue(Action.NAME, "Italic");
    styleMenu.add(italicAction);

    menu.add(styleMenu);

    north.add(menu);
    north.add(print);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(north, BorderLayout.NORTH);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(800, 500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:ec.nbdemetra.sa.revisionanalysis.RevisionAnalysisChart.java

private JMenu createPopupMenu() {
    JMenu result = new JMenu();
    result.add(newExportMenu());

    return result;
}

From source file:cz.nn.copytables.gui.CopyTablesGUI.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Rudolf Rada
    ResourceBundle bundle = ResourceBundle.getBundle("locale");
    menuBar = new JMenuBar();
    menuFile = new JMenu();
    menuItemOpenFile = new JMenuItem();
    menuItemCloseFile = new JMenuItem();
    menuItemConfig = new JMenuItem();
    menuHelp = new JMenu();
    menuItemHelp = new JMenuItem();
    menuItemAbout = new JMenuItem();
    CellConstraints cc = new CellConstraints();

    //======== this ========
    setBackground(new Color(204, 255, 204));

    // JFormDesigner evaluation mark
    setBorder(/*ww  w  .  ja  v  a2 s.c om*/
            new javax.swing.border.CompoundBorder(
                    new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
                            "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
                            javax.swing.border.TitledBorder.BOTTOM,
                            new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.red),
                    getBorder()));
    addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent e) {
            if ("border".equals(e.getPropertyName()))
                throw new RuntimeException();
        }
    });

    setLayout(new FormLayout("default", "default, $lgap, default"));

    //======== menuBar ========
    {

        //======== menuFile ========
        {
            menuFile.setText(bundle.getString("CopyTablesGUI.menuFile.text"));

            //---- menuItemOpenFile ----
            menuItemOpenFile.setText(bundle.getString("CopyTablesGUI.menuItemOpenFile.text"));
            menuItemOpenFile.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    menuItem2ActionPerformed(e);
                }
            });
            menuFile.add(menuItemOpenFile);

            //---- menuItemCloseFile ----
            menuItemCloseFile.setText(bundle.getString("CopyTablesGUI.menuItemCloseFile.text"));
            menuItemCloseFile.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    menuItem3ActionPerformed(e);
                }
            });
            menuFile.add(menuItemCloseFile);

            //---- menuItemConfig ----
            menuItemConfig.setText(bundle.getString("CopyTablesGUI.menuItemConfig.text"));
            menuItemConfig.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    menuItem4ActionPerformed(e);
                }
            });
            menuFile.add(menuItemConfig);
        }
        menuBar.add(menuFile);

        //======== menuHelp ========
        {
            menuHelp.setText(bundle.getString("CopyTablesGUI.menuHelp.text"));

            //---- menuItemHelp ----
            menuItemHelp.setText(bundle.getString("CopyTablesGUI.menuItemHelp.text"));
            menuItemHelp.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    menuItemHelpActionPerformed(e);
                }
            });
            menuHelp.add(menuItemHelp);

            //---- menuItemAbout ----
            menuItemAbout.setText(bundle.getString("CopyTablesGUI.menuItemAbout.text"));
            menuItemAbout.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    menuItemAboutActionPerformed(e);
                }
            });
            menuHelp.add(menuItemAbout);
        }
        menuBar.add(menuHelp);
    }
    add(menuBar, cc.xy(1, 1));
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:de.javagl.jgltf.browser.MenuNodes.java

/**
 * Create a list of menu items (which may be JMenu instances) for the 
 * given {@link MenuNode} instances.  /*from   ww w.  j a v a  2s  .  com*/
 * 
 * @param menuNodes The {@link MenuNode}s
 * @return The menus
 */
private static List<JMenuItem> createMenuItems(List<? extends MenuNode> menuNodes) {
    List<JMenuItem> menuItems = new ArrayList<JMenuItem>();

    for (MenuNode menuNode : menuNodes) {
        if (menuNode.children != null) {
            JMenu menu = new JMenu();
            menu.setText(menuNode.label);

            List<JMenuItem> childMenuItems = createMenuItems(menuNode.children);
            for (JMenuItem childMenuItem : childMenuItems) {
                menu.add(childMenuItem);
            }
            menuItems.add(menu);
        } else {
            if (menuNode.command == null) {
                logger.warning("Empty menu node - skipping");
                continue;
            }
            JMenuItem menuItem = new JMenuItem();
            String label = "<html>" + menuNode.label + " <font size=-2>(" + menuNode.command + ")</font>"
                    + "</html>";
            menuItem.setText(label);
            menuItem.setActionCommand(menuNode.command);
            menuItems.add(menuItem);
        }

    }
    return menuItems;
}