Solved

BorderLayout with MenuBar override Component

Posted on 1997-07-17
1
488 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

734 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