0
JComboBox
有一個add(PopUpMenu)
和add(JMenuItem)
。JCombo中的子菜單
我的課程擴展了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);
}
我將這些項目添加到JMenus,然後將它們添加到PopUpMenu中,以便JMenus成爲子菜單。我試圖完成的是一個JComboBox,當你點擊它時,你可以訪問嵌套的項目。任何想法如何實現這一目標? – user489041 2011-03-15 19:29:15
看到我的編輯,我想我看着它走錯了路。 – 2011-03-15 19:34:53