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(U IManager.g etSystemLo okAndFeelC lassName() );
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(statusPane l, BorderLayout.SOUTH);
this.setJMenuBar(new AnywhereMenuBar());
this.setDefaultCloseOperat ion(JFrame .EXIT_ON_C LOSE);
this.setTitle("Anywhere");
this.pack();
this.setVisible(true);
}
Thankful for help,
emelin
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(U
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,
contentPane.add(navPanel, BorderLayout.NORTH);
contentPane.add(browser, BorderLayout.CENTER);
contentPane.add(statusPane
this.setJMenuBar(new AnywhereMenuBar());
this.setDefaultCloseOperat
this.setTitle("Anywhere");
this.pack();
this.setVisible(true);
}
Thankful for help,
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("Bookmar ks");
bookmarkMenu.readBookmarks ();
Action actionQuit = new AbstractAction("Exit") {
public void actionPerformed(ActionEven t evt) {
System.exit(0);
}
};
fileMenu.add(new JMenuItem(actionQuit));
this.add(fileMenu);
this.add(bookmarkMenu);
}
}
Looks like this:
public class AnywhereMenuBar extends JMenuBar {
/**
* Creates the AnywhereMenuBar
*/
public AnywhereMenuBar() {
super();
JMenu fileMenu = new JMenu("File");
AnywhereBookmarks bookmarkMenu = new AnywhereBookmarks("Bookmar
bookmarkMenu.readBookmarks
Action actionQuit = new AbstractAction("Exit") {
public void actionPerformed(ActionEven
System.exit(0);
}
};
fileMenu.add(new JMenuItem(actionQuit));
this.add(fileMenu);
this.add(bookmarkMenu);
}
}
Does any of your components extend an AWT component?
ASKER
(AnywhereBookmarks extends JMenu)
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(brow serRendere r);
Dimension screenDim = Toolkit.getDefaultToolkit( ).getScree nSize();
browser.setPreferredSize(n ew Dimension(screenDim.width - 200,
screenDim.height - 200));
browser.setURL(new URL(url));
return browser;
}
Any relevance?
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(brow
Dimension screenDim = Toolkit.getDefaultToolkit(
browser.setPreferredSize(n
screenDim.height - 200));
browser.setURL(new URL(url));
return browser;
}
Any relevance?
>>Any relevance?
No.
Do you have any custom painting being done?
No.
Do you have any custom painting being done?
>> this.pack();
What happens on removing it?
What happens on removing it?
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(); 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.]
Just removing pack won't do it.You need to setSize(200, 200) [e.g.]
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...
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Might be... I'll check it out.
ASKER
I fixed it!
I had to do the following to my JMenus:
fileMenu.getPopupMenu().se tLightWeig htPopupEna bled(false );
bookmarkMenu.getPopupMenu( ).setLight WeightPopu pEnabled(f alse);
Thanks for your help, CEHJ! You get the points for being there for discussion! :)
I had to do the following to my JMenus:
fileMenu.getPopupMenu().se
bookmarkMenu.getPopupMenu(
Thanks for your help, CEHJ! You get the points for being there for discussion! :)
:-)
What class does this extend