JMenuBar disappears after adding ...

  • Follow


I used in the main frame
this.setJMenuBar(mb);

and I also tried
pane.getContentPane();
....
pane.add(mb, BorderLayout.NORTH);

when I add a JPanel in the center, the menu bar disappears.
this JPanel component uses Java2D features (some drawing) , and can
play sound in some conditions.

Although the menu bar is initially invisible, I click on the place
where the menu supposedly located and the menu reappears.

Can somebody please give suggestions on how to fix the bug?

0
Reply ericwan78 (35) 11/1/2006 12:53:10 AM

wanwan wrote:
> I used in the main frame
> this.setJMenuBar(mb);
>
> and I also tried
> pane.getContentPane();
> ...
> pane.add(mb, BorderLayout.NORTH);

Are you programming using some instruction
manual/documentation, or a cook-book?

What is it, you expect the above code to do?

>From where I'm sitting, it apperas you throw
away the reference to the content pane and
proceed to add the mb directly to the root
frame or window (whatever).

> Can somebody please give suggestions on how to fix the bug?

The most important help for fixing this bug,
would probably be for you to work through 
the GUI tutorial.

Andrew T.

0
Reply Andrew 11/1/2006 2:40:41 AM


wow, Andrew, you're good.  You've been very helpful for my last few
questions.  For this problem, I found out it was caused by a null
object in the jpanel component.

> Are you programming using some instruction
> manual/documentation, or a cook-book?
>
I'm programming from experience.  I've been writing GUI with Java for 5
years.  From time to time, I need new things, or just need some quick
answers.

> What is it, you expect the above code to do?
>
I'm making a game ... first time I am dealing with Java2D


Thanks for your help.

0
Reply wanwan 11/1/2006 7:30:38 PM

2 Replies
174 Views

(page loaded in 0.045 seconds)


Reply: