Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

urgent help with adding a Jmenu to a JComboBox

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to add a JMenu to a JComboBox which in turn is added to a
JTable, but nothing is showing in the JComboBox.The comboBox will
have several choices and then in turn I would like to add other options to those this is my code. All help is greatly appreciated

JComboBox comboBox = new JComboBox();

addNewMenu("1");
addNewMenu("2");
addNewMenu("3");
private void addNewMenu(String s) {

JMenu m = (JMenu)comboBox.add(new HorizontalMenu(s));
m.add("a");
m.add("b");
m.add("c");
}
class HorizontalMenu
{
public HorizontalMenu(String label) {
super(label);
JPopupMenu pm = getPopupMenu();
pm.setLayout(new BoxLayout(pm, BoxLayout.X_AXIS));
setMinimumSize(getPreferredSize());
setPopupMenuVisible(true);
}
public void setPopupMenuVisible(boolean b) {
boolean isVisible = isPopupMenuVisible();
if(b != isVisible())
{
if((b==true) && isShowing())
{
int x = 0;
int y = 0;
Container parent = getParent();
if(parent instanceof JPopupMenu)
{
x = 0;
y = getHeight();
}
else
{
x = getWidth();
y = 0;
}
getPopupMenu().show(this, x, y);

}
else
{
getPopupMenu().setVisible(true);
}
}
}
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using JMenu to accomplish this?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic