Подменю в JCombo - PullRequest
       26

Подменю в JCombo

0 голосов
/ 15 марта 2011

JComboBox имеет add(PopUpMenu) и add(JMenuItem).

Мой класс расширяет JComboBox. Я создаю JPopUpMenu, но он не отображается при нажатии на JComboBox. Вместо этого ничего не отображается. Есть идеи?



    JPopupMenu Pmenu = new JPopupMenu();
    JMenu textAndDataMenu = new JMenu("Text and Data");

    HashMap textAndData = new HashMap();

    public ComboMenu()
    {
        super();
        setUpTextAndData();
        add(Pmenu);  //----------this is where I add the menu

    }

    public void setUpTextAndData()
    {
        textAndData.put("Basic Text Box", TextBox.class);
        textAndData.put("Clear Text Box", ClearTextBox.class);
        textAndData.put("Table", Table.class);
        textAndData.put("Interactive Table", InteractiveTable.class);
        textAndData.put("Graph", Graph.class);

        Set textAndDataKeys = textAndData.keySet();
        JMenuItem newMenuItem;
        for(String currKey : textAndDataKeys)
        {
            newMenuItem = new JMenuItem(currKey);
            newMenuItem.addActionListener(this);
            textAndDataMenu.add(newMenuItem);
        }

        Pmenu.add(textAndDataMenu);
    }

1 Ответ

0 голосов
/ 15 марта 2011

РЕДАКТИРОВАТЬ: Неважно ... вы знаете, я уже давно с ними не связывался.

Я думаю, все что вам нужно сделать это:

Pmenu.setInvoker(this);

перед добавлением в конструктор.

...