Example usage for javax.swing JMenu isPopupMenuVisible

List of usage examples for javax.swing JMenu isPopupMenuVisible

Introduction

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

Prototype

public boolean isPopupMenuVisible() 

Source Link

Document

Returns true if the menu's popup window is visible.

Usage

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("File");
    ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT;

    menu.applyComponentOrientation(ori);
    bar.add(menu);/*ww w. j  a va 2  s .  c om*/

    menu.add(new JMenuItem("Close"));
    menu.add(new JSeparator()); // SEPARATOR
    menu.add(new JMenuItem("Exit"));

    setJMenuBar(bar);
    add(new JLabel("A placeholder"));

    pack();
    setSize(300, 300);
    setVisible(true);

    menu.isPopupMenuVisible();
}

From source file:ca.sqlpower.swingui.object.VariablesPanel.java

@SuppressWarnings("unchecked")
private void showVarsPicker() {
    final MultiValueMap namespaces = this.variableHelper.getNamespaces();

    List<String> sortedNames = new ArrayList<String>(namespaces.keySet().size());
    sortedNames.addAll(namespaces.keySet());
    Collections.sort(sortedNames, new Comparator<String>() {
        public int compare(String o1, String o2) {
            if (o1 == null) {
                return -1;
            }//from   w w  w.j av  a  2  s .  c om
            if (o2 == null) {
                return 1;
            }
            return o1.compareTo(o2);
        };
    });

    final JPopupMenu menu = new JPopupMenu();
    for (final String name : sortedNames) {
        final JMenu subMenu = new JMenu(name);
        menu.add(subMenu);
        subMenu.addMenuListener(new MenuListener() {
            private Timer timer;

            public void menuSelected(MenuEvent e) {

                subMenu.removeAll();
                subMenu.add(new PleaseWaitAction());

                ActionListener menuPopulator = new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        if (subMenu.isPopupMenuVisible()) {
                            subMenu.removeAll();
                            for (Object namespaceO : namespaces.getCollection(name)) {
                                String namespace = (String) namespaceO;
                                logger.debug("Resolving variables for namespace ".concat(namespace));
                                int nbItems = 0;
                                for (String key : variableHelper.keySet(namespace)) {
                                    subMenu.add(new InsertVariableAction(SPVariableHelper.getKey((String) key),
                                            (String) key));
                                    nbItems++;
                                }
                                if (nbItems == 0) {
                                    subMenu.add(new DummyAction());
                                    logger.debug("No variables found.");
                                }
                            }
                            subMenu.revalidate();
                            subMenu.getPopupMenu().pack();
                        }
                    }
                };
                timer = new Timer(700, menuPopulator);
                timer.setRepeats(false);
                timer.start();
            }

            public void menuDeselected(MenuEvent e) {
                timer.stop();
            }

            public void menuCanceled(MenuEvent e) {
                timer.stop();
            }
        });
    }

    menu.show(varNameText, 0, varNameText.getHeight());
}