Solved

BorderLayout with MenuBar override Component

Posted on 1997-07-17
1
460 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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ā€¦
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.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.

708 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

15 Experts available now in Live!

Get 1:1 Help Now