Submenu in JCombo
The JComboBox
has a add(PopUpMenu)
and a add(JMenuItem)
.
My class extends JComboBox. I create a JPopUpMenu, but it fails to display when I click on the JComboBox. Instead, nothing is displayed. Any ideas?
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", Intera开发者_开发知识库ctiveTable.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);
}
EDIT: Nevermind ... you know, I haven't messed with these in a while.
I think all you need to do is:
Pmenu.setInvoker(this);
before adding it in your constructor.
精彩评论