Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Cannot add MenuBar to Frame on Mac OS

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Cannot add MenuBar to Frame on Mac OS

    I am trying to add a menubar to a frame, when i execute the following program on Windows platform then i get the correct output where as the menubar does not appear in the frame if i execute it on Mac OS!!

     
    import java.awt.*;
    import java.awt.event.*;
    public class menuDemo extends Frame implements WindowListener{
    MenuBar mb;
    Menu m1,m2,m3;
    MenuItem mi1,mi2,mi3,mi4;
    menuDemo(){
    setLayout(new FlowLayout());
    setSize(500,500);
    mb=new MenuBar();
    m1=new Menu("File");
    m2=new Menu("New");
    m3=new Menu("Save");
    mi1=new MenuItem("one");
    mi2=new MenuItem("two");
    mi3=new MenuItem("three");
    mi4=new MenuItem("Four");
    Button b=new Button("hell");
    add(b);
    m1.add(mi1);
    m1.add(mi2);
    m2.add(mi3);
    m3.add(mi4);
    mb.add(m1);
    mb.add(m2);
    mb.add(m3);
    setMenuBar(mb);
    addWindowListener(this);
    setVisible(true);
    }
    public static void main(String ar[]){
    new menuDemo();
    }
    public void windowClosed(WindowEvent we){}
    public void windowClosing(WindowEvent we){
    dispose();
    }
    public void windowOpened(WindowEvent we){}
    public void windowActivated(WindowEvent we){}
    public void windowDeactivated(WindowEvent we){}
    public void windowIconified(WindowEvent we){}
    public void windowDeiconified(WindowEvent we){}
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Cannot add MenuBar to Frame on Mac OS

    a) Any reason you are using AWT rather than Swing (same components with the 'J' prefix). b) Create your GUI on the EDT by dispatching its creation to SwingUtilities.invokeAndWait in the main method c) Call pack() on the JFrame to pack all the components.

Similar Threads

  1. Trouble with Java menubar in java frame.
    By Jullix993 in forum AWT / Java Swing
    Replies: 4
    Last Post: April 16th, 2013, 07:10 AM
  2. Removing MenuBar in awt
    By saurabh_kabra in forum AWT / Java Swing
    Replies: 0
    Last Post: March 29th, 2013, 01:33 PM
  3. Replies: 1
    Last Post: January 19th, 2012, 03:44 PM
  4. MenuBar in Java?
    By xTommy24 in forum AWT / Java Swing
    Replies: 2
    Last Post: October 12th, 2011, 03:27 PM
  5. applet menubar
    By tabutcher in forum Java Applets
    Replies: 2
    Last Post: March 5th, 2010, 09:30 AM