Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu hiden Problem

Status
Not open for further replies.

mfc2005

Programmer
Jul 25, 2005
8
GB
I have a JFrame containing a JTabbedPane with 2 tabs and a JMenubar with a few menus and menu items. When I click on the menus when tab1 is highlighted everything behaves how it should in the ordering, but when I click on tab2 (which has a painted canvas on it) I find the menu is hidden behind the canvas. Is this due to the stacking order?

 
Ah realised it was to do with mixing Light and heavy components (I assume canvas is a heavyweight component).
Is there an equivalent swing component (have checked don't think there is). If not how do I get round problems of showing a canvas inside a panel which is inside a JTabbedPane? Currently I have a Jframe, contentPane container, JTabbedPane, JPanel and then finally my drawing canvas (in that order). unfortunately when I start my program it doesn't display anything from my canvas class, which I know work if I just add the canvas to the contentPane. Is it because the canvas heavy component is falling through?
 
Code:
import java.awt.*;

import javax.swing.*;
public class MixPopupTest extends JFrame {
    public MixPopupTest() {
       super("Mix Popup Test");
       JMenuBar menubar = new JMenuBar();
       setJMenuBar(menubar);
       // Create lightweight-enabled menu
       JMenu menu = new JMenu("Lite Menu");
       menu.add("Salad");
       menu.add("Fruit Plate");
       menu.add("Water");
       menubar.add(menu);
       // Create lightweight-disabled menu
       JPopupMenu.
          setDefaultLightWeightPopupEnabled
          (false);
       menu = new JMenu("Heavy Menu");
       menu.add("Filet Mignon");
       menu.add("Gravy");
       menu.add("Banana Split");
       menubar.add(menu);
       // Create Heavyweight AWT Button
       Button heavy = new Button
           ("  Heavyweight Button  ");
       // Add heavy button to box
       Box box = Box.createVerticalBox();
       box.add(Box.createVerticalStrut(20));
       box.add(heavy);
       box.add(Box.createVerticalStrut(20));
       getContentPane().add("Center", box);
       pack();
    }
    public static void main(String[] args) {
        MixPopupTest t = new MixPopupTest();
        t.show();
    }
}
// i think this line will help you
JPopupMenu. setDefaultLightWeightPopupEnabled (false);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top