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 5 of 5

Thread: the output is just a blank frame... no menu bar is present.. plz help me out..

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post the output is just a blank frame... no menu bar is present.. plz help me out..

    import javax.swing.*;
    public class MyClass {

    public static void main(String[] args)throws Exception {
    new Extra();

    }

    }
    class Extra extends JFrame
    {
    JMenuBar mb;
    JMenu File,View,Settings,Audio,Video,Help;
    JMenuItem OpenFile,OpenDirectory,OpenDisc,Exit,PlayList, Messages,SwitchInterface,AddInterface,Bookmarks,Pr eferences,About;

    Extra()
    {

    super("VLC Player");
    setLayout(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mb=new JMenuBar();
    File=new JMenu("File");
    View=new JMenu("View");
    Settings=new JMenu("Settings");
    Audio=new JMenu("Audio");
    Video=new JMenu("Video");
    Help=new JMenu("Help");
    OpenFile=new JMenuItem("Open File");
    OpenDirectory=new JMenuItem("Open Directory");
    OpenDisc=new JMenuItem("Open Disc");
    Exit=new JMenuItem("Exit");
    PlayList=new JMenuItem("PlayList");
    Messages=new JMenuItem("Messages");
    SwitchInterface=new JMenuItem("Switch Interface");
    AddInterface=new JMenuItem("Add Interface");
    Bookmarks=new JMenuItem("Bookmarks");
    Preferences=new JMenuItem("Preferences");
    About=new JMenuItem("About");
    mb.add(File);
    mb.add(View);
    mb.add(Settings);
    mb.add(Help);
    File.setBounds(0, 0, 5,2 );
    File.add(OpenFile);
    File.add(OpenDirectory);
    File.add(OpenDisc);
    File.add(Exit);
    View.add(PlayList);
    View.add(Messages);
    View.setBounds(5, 0, 5,2);
    Settings.add(SwitchInterface);
    Settings.add(AddInterface);
    Settings.add(Bookmarks);
    Settings.add(Preferences);
    Settings.setBounds(10,0,5,2);
    Help.add(About);
    Help.setBounds(15, 0, 5, 2);
    pack();
    setVisible(true);
    mb.setVisible(true);
    File.setVisible(true);
    View.setVisible(true);
    setSize(600,600);

    }

    }


  2. #2
    Junior Member Krumpir's Avatar
    Join Date
    Jul 2012
    Location
    Cape Town, South Africa
    Posts
    9
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: the output is just a blank frame... no menu bar is present.. plz help me out..

    Add the following line of code after setSize(600,600).

    setJMenuBar(mb);
    Check out my site -> tssolutions.net16.net

  3. The Following User Says Thank You to Krumpir For This Useful Post:

    namita (July 19th, 2012)

  4. #3
    Member
    Join Date
    Jul 2012
    Posts
    83
    My Mood
    Cynical
    Thanks
    3
    Thanked 9 Times in 9 Posts

    Default Re: the output is just a blank frame... no menu bar is present.. plz help me out..

    First look for obvious problems, such as: Where do you add the JMenuBar to the JFrame? JFrame has a method for this, setJMenuBar(...), and I don't see it being called anywhere.

    I suggest that you go through the Java Swing menus tutorials as this is all well explained there.

  5. #4
    Junior Member
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: the output is just a blank frame... no menu bar is present.. plz help me out..

    hey.. thnx alottt.. it worked.. cn u plzz tell me wat does setJMenuBar(mb) mean??

  6. #5
    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: the output is just a blank frame... no menu bar is present.. plz help me out..

    Quote Originally Posted by namita View Post
    hey.. thnx alottt.. it worked.. cn u plzz tell me wat does setJMenuBar(mb) mean??

    The API should be the first place you look: JFrame (Java Platform SE 6)
    If you don't understand the API, then ask a question about it. And a suggestion: this is a technical forum. Writing shorthand (plzz, wat, etc..) not only makes your posts that much harder to understand, but also can make you look lazy - not a trait you wish to portray when asking unpaid volunteers to spend their time helping you.

Similar Threads

  1. logic present tag
    By naval.gupta4u@gmail.com in forum Java Servlet
    Replies: 0
    Last Post: July 15th, 2012, 01:28 AM
  2. How to get Present working Directory(Exact path) in java..?
    By smilyface in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 8th, 2012, 03:42 PM
  3. Replies: 1
    Last Post: January 19th, 2012, 03:44 PM
  4. Games/Application (Video output, Frame, Graphics Components,Versatility)
    By chronoz13 in forum Java Theory & Questions
    Replies: 3
    Last Post: July 7th, 2011, 08:06 AM
  5. Is it possible to use card layout for menu and menu items?
    By jai2rul in forum AWT / Java Swing
    Replies: 0
    Last Post: April 11th, 2011, 08:19 AM