File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PopupMenu in Menu?

 
Chun Wang
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • 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);
}
}
 
Jane Griscti
Ranch Hand
Posts: 3141
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Zheng Huang
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic