JCombo 中的子菜单
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);
}
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", 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:没关系...你知道,我已经有一段时间没有搞乱这些了。
我认为您需要做的就是:
在将其添加到构造函数之前。
EDIT: Nevermind ... you know, I haven't messed with these in a while.
I think all you need to do is:
before adding it in your constructor.