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
432 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now