Link to home
Start Free TrialLog in
Avatar of emelin
emelin

asked on

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>AnywhereMenuBar

What class does this extend
Avatar of emelin
emelin

ASKER

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);
        }
}
Does any of your components extend an AWT component?
Avatar of emelin

ASKER

(AnywhereBookmarks extends JMenu)
Avatar of emelin

ASKER

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?
>>Any relevance?

No.

Do you have any custom painting being done?
>> this.pack();

What happens on removing it?
Avatar of emelin

ASKER

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.
>>On removing this.pack();

Just removing pack won't do it.You need to setSize(200, 200) [e.g.]
Avatar of emelin

ASKER

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...
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of emelin

ASKER

Might be... I'll check it out.
Avatar of emelin

ASKER

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! :)
:-)