Results 1 to 5 of 5
  1. #1
    corrax is offline Member
    Join Date
    Apr 2011
    Posts
    13
    Rep Power
    0

    Default JMenuBar not showing on a JFrame unless resized manually.

    Hi.
    I have searched for this, and found nothing similar.
    I am using a JFrame that contains a JMenuBar.
    The program works fine except that unless I resize the Frame manually, the MenuBar doesn't show.
    Anyone know how to fix this?

    Java Code:
    public class Move extends JFrame{
            private JMenuBar Menubar;
    
            public static void main(String [] args)
            {
    	     new Move("Move");
             }
             public Move (String name)  {   
    	     super(name);
    	     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	      this.pack();
    	      this.setSize(500,500);
    	      this.setLocation(600,500);
    	      this.setVisible(true);
    
                  Menubar = new JMenuBar();//The main menubar
    	      setJMenuBar(Menubar);
    
                  ...
             }
    }
    Thanks!

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Try packing and doing all the stuff that displays it after setting the menu.

  3. #3
    corrax is offline Member
    Join Date
    Apr 2011
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by sunde887 View Post
    Try packing and doing all the stuff that displays it after setting the menu.
    I tried that ,but it is the same output.

    I think that that menubar is hidden by the title area of the frame (where it has the close and minimize buttons, and the title)

  4. #4
    corrax is offline Member
    Join Date
    Apr 2011
    Posts
    13
    Rep Power
    0

    Default

    Fixed!

    I changed it to this.

    Java Code:
    public static void main(String [] args)
    	{
    		Move mo = new Move("Move");
    		mo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		mo.setVisible(true);
    	}
    	public Move (String name)  {   
    		super(name);
    		this.setSize(500,500);
    		this.setLocation(600,500);
                    
                    ...
            }

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    It looks like your fix just sets the visibility after adding the menu, I'm pretty sure that calls to lack, setSize and setVisible should be done after you have added everything to the frame. Either way, glad you solved it.

Similar Threads

  1. JMenuBar error
    By Tastosis in forum New To Java
    Replies: 6
    Last Post: 03-02-2011, 11:55 AM
  2. Mutliple JMenuBar
    By chyrl in forum AWT / Swing
    Replies: 10
    Last Post: 11-04-2010, 05:43 AM
  3. JPanel not showing up in JFrame
    By rlindsey in forum AWT / Swing
    Replies: 2
    Last Post: 06-25-2010, 07:21 AM
  4. JMenubar option
    By navishkumarb in forum New To Java
    Replies: 3
    Last Post: 05-24-2010, 02:03 AM
  5. Replies: 1
    Last Post: 02-20-2009, 03:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •