Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes Dynamically changing a JMenuBar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamically changing a JMenuBar" Watch "Dynamically changing a JMenuBar" New topic

Dynamically changing a JMenuBar

Christian Waidner

Joined: Mar 29, 2001
Posts: 6
I have an applet running which displays a JMenuBar. I wonder if there is any way to change the menu while the application is running. I tried another call to the applet's setJMenuBar(mymenu) but then all menus just disappear.
I have not overridden any paint methods, so where's the problem?
Thanks in advance,

Christian Waidner<BR>Hirschbiegel & Grundstein GmbH<BR>
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You were, of course, adding this JMenuBar to a JApplet, not a regular Applet? Maybe you could try:

before adding the new one. Then after it is added, you could also make a call to getMenuBar() just to see if it worked.
Christian Waidner

Joined: Mar 29, 2001
Posts: 6
Yep, JApplet.
I solved this problem 10 minutes ago. Seems to be the old Swing updating problem (grrrrrrr). Just invalidate every component except the last one, the validate and it's ok.
It is sorta covered in the JavaRanch Style Guide.
subject: Dynamically changing a JMenuBar
Similar Threads
JMenuBar not using default alignment?
Run JApplet and no JMenuBar - Help!!
Setting the null layout for JMenuBar in JApplet
JApplet containing JTextfields within a JMenubar