Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

BorderLayout with MenuBar override Component

Posted on 1997-07-17
1
Medium Priority
?
506 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 80 total points
ID: 1223243
Just before

window.show();

add in

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

926 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