Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 661
  • Last Modified:

JPanel overlaps JMenuBar - how fix it?

Hello!

I have an annoying little problem I hope someone can help me with. I have set up a JFrame window to which I'm adding some stuff, for example a JMenuBar and a Browser object, which extends a JPanel (I'm required to use the Browser as is). When I open the JMenuBar I can only see the very top of it, as the Browser/JPanel overlaps it. Is there a way to set the JMenuBar to be shown on top instead?

My window is set up like this:

    public void activate() throws Exception {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        Container contentPane = this.getContentPane();
        contentPane.setLayout(new BorderLayout());
        Browser browser = createBrowser();
        AnywhereNavPanel navPanel = new AnywhereNavPanel(browser);
        AnywhereStatusBar statusBar = new AnywhereStatusBar(browser);
        JPanel statusPanel = new JPanel();
        statusPanel.setLayout(new BorderLayout());
        statusPanel.add(statusBar, BorderLayout.WEST);
        contentPane.add(navPanel, BorderLayout.NORTH);        
        contentPane.add(browser, BorderLayout.CENTER);
        contentPane.add(statusPanel, BorderLayout.SOUTH);
        this.setJMenuBar(new AnywhereMenuBar());
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("Anywhere");
        this.pack();
        this.setVisible(true);
    }

Thankful for help,
emelin
0
emelin
Asked:
emelin
  • 7
  • 6
1 Solution
 
CEHJCommented:
>>AnywhereMenuBar

What class does this extend
0
 
emelinAuthor Commented:
JMenuBar

Looks like this:

public class AnywhereMenuBar extends JMenuBar {

    /**
     * Creates the AnywhereMenuBar
     */
    public AnywhereMenuBar() {
        super();
        JMenu fileMenu = new JMenu("File");
        AnywhereBookmarks bookmarkMenu = new AnywhereBookmarks("Bookmarks");
        bookmarkMenu.readBookmarks();        
        Action actionQuit = new AbstractAction("Exit") {
            public void actionPerformed(ActionEvent evt) {
                System.exit(0);
            }
        };
        fileMenu.add(new JMenuItem(actionQuit));
        this.add(fileMenu);
        this.add(bookmarkMenu);
        }
}
0
 
CEHJCommented:
Does any of your components extend an AWT component?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
emelinAuthor Commented:
(AnywhereBookmarks extends JMenu)
0
 
emelinAuthor Commented:
No, they don't extend awt components.

I have some awt... Container is awt:
...
Container contentPane = this.getContentPane();
...
contentPane.add(navPanel, BorderLayout.NORTH);

And for setting up the Browser I use awt.Dimension like this:

    private Browser createBrowser() throws Exception {
        Browser browser = Browser.createBrowser(browserRenderer);
        Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
        browser.setPreferredSize(new Dimension(screenDim.width - 200,
                                               screenDim.height - 200));
        browser.setURL(new URL(url));
        return browser;
    }

Any relevance?
0
 
CEHJCommented:
>>Any relevance?

No.

Do you have any custom painting being done?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> this.pack();

What happens on removing it?
0
 
emelinAuthor Commented:
I don't do any custom painting, if that's what I think it is. Should I use repaint on something?

On removing this.pack(); I get just a title bar saying "Anywhere", no window, nothing else.
0
 
CEHJCommented:
>>On removing this.pack();

Just removing pack won't do it.You need to setSize(200, 200) [e.g.]
0
 
emelinAuthor Commented:
Okay. I tried replacing this.pack() to with a this.setSize(..), but it does the same thing.

I just realized something though...

What Browser does is adding a html renderer based on input arguments, jdic or swing. When it adds a SwingBrowser (extending Browser extending JPanel) the menu shows just fine, but it doesn't work for JdicBrowser which is my default. Can't see what's the difference though...

API: http://hnu.ida.liu.se/pp-verkstad/resurs/api/ 

Sorry this is getting stranger and stranger...
0
 
CEHJCommented:
Could be that JdicBrowser is buggy. Does it fail on different machines/jres?
0
 
emelinAuthor Commented:
Might be... I'll check it out.
0
 
emelinAuthor Commented:
I fixed it!

I had to do the following to my JMenus:

        fileMenu.getPopupMenu().setLightWeightPopupEnabled(false);
        bookmarkMenu.getPopupMenu().setLightWeightPopupEnabled(false);

Thanks for your help, CEHJ! You get the points for being there for discussion! :)
0
 
CEHJCommented:
:-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now