• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PopupMenu in Menu?

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
as far as I understand, objects of MenuItem and its subclasses can be
added to a Menu. that means PopupMenu can be added to a Menu too since
PopupMenu is a subclass of MenuItem. so I wrote the following test
code and it compiles. but I couldn't see the popup menu showing on my
menubar. can anyone tell me why? thanks a lot.
cw
===============================
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class A extends Frame {
public static void main(String[] args) {
Frame a = new A();
MenuBar mb = new MenuBar();
Menu m = new Menu("Menu");
CheckboxMenuItem cbmi = new CheckboxMenuItem("check");
MenuItem mi1 = new MenuItem("first");
MenuItem mi2 = new MenuItem("second");
PopupMenu pm = new PopupMenu("Pop");
pm.add("pop1");
pm.add("pop2");
m.add(cbmi);
m.add(mi1);
m.add(mi2);
m.add(pm);
mb.add(m);
a.setMenuBar(mb);
a.setSize(250,250);
a.setVisible(true);
}
}
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chun,
You added the Popup menu to 'menu' not the menubar.
Change 'm.add(pm)' to 'mb.add(pm)
Hope that helps.
------------------
Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
 
Chun Wang
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jane!
but can I have a Popupmenu nested in a Menu? if so, how? please help. thanks.
chun
 
Chun Wang
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Jane.
I just tried adding popupmenu to the menubar. but the whole menu became a popup menu instead of a pull-down menu. my question is can you have a pull-down menu as well as a popupmenu in the menubar? can you have a popupmenu nested in a pull-down menu? if so, how? thanks a lot.
chun
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, chun.
I tried your code and Jane's suggestion. The pop-up menu can be added to menu and menubar. What version of JVM do you use?
Zheng
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chun,
You're example had the popupmenu as part of the menu in the menubar. You can use a popupmenu anywhere you would use a menu.
Here's an example I fudged from examples in the Class Libraries

Hope that helps.
------------------
Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic