Solved

BorderLayout with MenuBar override Component

Posted on 1997-07-17
1
476 Views
Last Modified: 2008-02-26
In the following code using BorderLayout if I use MenuBar, it seems to override part of my TextField component.
If I remove the MenuBar, the component appears OK.
After I resize the window, both Menu and Text appears ok.
Why? How can I make it appear correctly at the first time.
I've already tested with JDK 1.1.3 (make sure it's not a fixed bug)

Thanks

Jonny Oenning


// here goes the code
import java.awt.*;

public class GUIWindow extends Frame {
  public GUIWindow() {
    Panel bottomPanel = new Panel();
    BorderLayout bl = new BorderLayout();
    setLayout(bl);

    MenuBar mb = new MenuBar();
    Menu m1 = new Menu("Item 1");
    MenuItem m11 = new MenuItem("Item 1.1");
    setMenuBar(mb);
    mb.add(m1);
    m1.add(m11);

    bottomPanel.add(new Label("Label"));
    bottomPanel.add(new TextField("TextField"));
    add("South", bottomPanel);
  }

    public boolean handleEvent(Event event) {
       if (event.id == Event.WINDOW_DESTROY) {
          System.exit(0);
       }
       return super.handleEvent(event);
    }

    public static void main(String args[]) {
        GUIWindow window = new GUIWindow();

        window.setTitle("Testing");
        window.pack();
        window.show();
    }
}




0
Comment
Question by:Jonny071797
1 Comment
 
LVL 2

Accepted Solution

by:
webster030697 earned 20 total points
ID: 1223243
Just before

window.show();

add in

window.resize(window.preferredSize());
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
print map entry 34 72
Chrome and Firefox Java 5 51
Is there a simpler dropbox system? 10 34
How to configure empty element in XML Document parser? 15 36
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

832 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