Solved

Bottom JMenuItems go behind JTabbedPane that is directly below this main menu when the first tab in the JTabbedPane is selected

Posted on 2006-11-28
6
446 Views
Last Modified: 2010-07-27
I am working with a Java Swing GUI.  I have a JMenuBar on the main JFrame with JMenus and JMenuItems.  Directly below this menu bar I have a JTabbedPane.  When I expand the menus in the Main Menu the bottom menu items disappear behind the JTabbedPane when the first tab in the JTabbedPane is selected.  When the second tab in the JTabbedPane is selected everything is fine.  How do I fix this?

Thanks,
Dave
0
Comment
Question by:gdkinney_2
6 Comments
 
LVL 10

Accepted Solution

by:
ADSLMark earned 250 total points
ID: 18030288
Example code:

import java.awt.*;
import javax.swing.*;

public class TabMenuExample extends JFrame
{
    public TabMenuExample()
    {
        this.setJMenuBar(CreateMenuBar());
        getContentPane().add(CreateTabbedPane());
        this.setSize(800,600);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    public JTabbedPane CreateTabbedPane()
    {
        JTabbedPane tab = new JTabbedPane();

        for(int i=0;i<10;i++)
        {
            JPanel pnl = new JPanel();
            tab.addTab("Tab" + i, null, pnl, "Tab" + i);
        }
        tab.setSelectedIndex(0);
        return tab;
    }

    public JMenuBar CreateMenuBar()
    {
        JMenuBar menubar = new JMenuBar();
        JMenu menu = new JMenu("Testing Menus");

        for(int i=0;i<10;i++)
        {
            JMenuItem menuitem = new JMenuItem("Menu Items " + i);
            menu.add(menuitem);
        }
        menubar.add(menu);
        return menubar;

    }

    public static void main(String[] args)
    {
        TabMenuExample test = new TabMenuExample();
        test.setVisible(true);
    }
}

Works for me, using java version 1.5.0_09.

Mark
0
 
LVL 14

Assisted Solution

by:hoomanv
hoomanv earned 250 total points
ID: 18031375
The problem is that you are mixing awt (heavy weight) and swing (light weight) components and that heavies win the competition and stay on top
http://java.sun.com/products/jfc/tsc/articles/mixing/
0
 

Author Comment

by:gdkinney_2
ID: 18031670
hoomany,
   I think you are correct we are using a GOTS product that I believe has AWT components.  I emailed the developers today to confirm this.  I'll check back tomorrow if my assumption is correct.
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question