Solved

BorderLayout with MenuBar override Component

Posted on 1997-07-17
1
483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Unhandled exception type Exception 18 63
Delete .class files at every compile 4 55
JVM error from eclipse 1 23
Java regex 5 18
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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.
Suggested Courses

739 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