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

Thread: menu bar is not appearing

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    10
    My Mood
    Inspired
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool menu bar is not appearing

    import java.awt.*;
    import javax.swing.JPanel;
    import java.awt.event.*;
    //import java.Color;
    public class Project_notepad implements MouseListener,MouseMotionListener
    {
    		public Frame f;		//basic frame
    	public MenuBar mb;		//menubar declaration
    	private Menu File, Edit, Format,View, Findit;
    	private MenuItem new_file,new_window,open,save,save_as, close, cut, copy, paste, case_convert, indent,font,style,size,underline,italic,bold,finds, incremental_find,replace;
    	private CheckboxMenuItem status_bar,word_wrap,hide_menu_bar,full_screen;
    	Label l1_menushow=new Label("show menu",Label.RIGHT);			//create label for menu show/hide
    	Panel p1_menushow=new Panel();					//create panel for top part to use with label
     
    	public Project_notepad()
    	{
     
    		f=new Frame();
    		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();			//Dimension class object for setting max screen size
          	f.setBounds(0,0,screenSize.width, screenSize.height);						
     
    		p1_menushow.setLayout(new BorderLayout());
     
     
     
    		l1_menushow.setSize(5,5);
     
     
    		p1_menushow.add(l1_menushow,BorderLayout.NORTH);						//add label to top panel
     
    		//l1_menushow.setVisible(false);
     
     
    		f.addMouseListener(this);
    		f.addMouseMotionListener(this);
    		f.add(p1_menushow);
          	f.setVisible(true);
    	}
     
     
    	public void mouseEntered(MouseEvent e)
    	{
    		Object o=e.getSource();
    		if(o==l1_menushow)
    		{
    			create_menu();
    		}
    	}
    	public void mouseExited(MouseEvent e)
    	{
    		Object o=e.getSource();
    		if(o==l1_menushow)
    		{
    			//f.removeMenuBar();
     
    		}
    	}
    	public void mouseClicked(MouseEvent e)
    	{
    		Object o=e.getSource();
    		if(o==l1_menushow)
    		{
    			create_menu();
    		}
    	}
    	public void mousePressed(MouseEvent e)
    	{
     
    	}
    	public void mouseReleased(MouseEvent e)
    	{
     
    	}
    	public void mouseMoved(MouseEvent e)
    	{
     
    	}
    	public void mouseDragged(MouseEvent e)
    	{
     
    	}
     
     
    	private void create_menu()									
    	{															//menu bar creation
    		mb=new MenuBar();										//menu bar declaration
          	File=new Menu("File");
          	Edit=new Menu("Edit");
          	Format=new Menu("Format");
          	View=new Menu("View");
          	Findit=new Menu("Find");
     
          	new_file=new MenuItem("new file");						//menu items declaration
          	new_window=new MenuItem("new window");
          	open=new MenuItem("open");
          	save=new MenuItem("save");
          	save_as=new MenuItem("save as");
          	close=new MenuItem("close");
          	cut=new MenuItem("cut");
          	copy=new MenuItem("copy");
          	paste=new MenuItem("paste");
          	case_convert=new MenuItem("case convert");
          	indent=new MenuItem("indent");
          	font=new MenuItem("font");
          	style=new MenuItem("style");
          	size=new MenuItem("size");
          	underline=new MenuItem("underline");
          	italic=new MenuItem("italic");
          	bold=new MenuItem("bold");
          	incremental_find=new MenuItem("incremental_find");
          	replace=new MenuItem("replace");
          	finds = new MenuItem("finds");
          	status_bar=new CheckboxMenuItem("status bar");							//chechkbox items declaration
          	word_wrap=new CheckboxMenuItem("word wrap");
          	hide_menu_bar=new CheckboxMenuItem("hide menu bar");
          	full_screen=new CheckboxMenuItem("full screen");
     
     
          	File.add(new_file);												//adding items to menu bar
          	File.add(new_window);
          	File.add(open);
          	File.add(save);
          	File.add(save_as);
          	File.add(close);
          	Edit.add(copy);
    		Edit.add(paste);
    		Edit.add(case_convert);
    		Edit.add(indent);
    		Format.add(font);
    		Format.add(style);
    		Format.add(size);
    		Format.add(underline);
    		Format.add(italic);
    		Format.add(bold);
    		Findit.add(finds);
    		Findit.add(incremental_find);
    		Findit.add(replace);
    		View.add(status_bar);
    		View.add(word_wrap);
    		View.add(hide_menu_bar);
    		View.add(full_screen);
     
     
    		mb.add(File);										
    		mb.add(Edit);
    		mb.add(Format);
    		mb.add(View);
    		mb.add(Findit);
     
    		f.setMenuBar(mb);
     
    	}
     
    	public static void main(String args[])
    	{
    		Project_notepad pr=new Project_notepad();
    	}
     
     
     
    }


    here i am trying to create menu bar.it appears when i move my mouse to label "show menu" and should disapper on removing.
    but there are two problems-
    1.menubar is not appearing.
    2.what is the method to remove entire menubar in awt package?
    thanks in advance.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: menu bar is not appearing

    Try debugging the code by adding some calls to the println() method to show where execution is going and to show the values of variables as they are used and changed.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    10
    My Mood
    Inspired
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: menu bar is not appearing

    but is there any way to remove entire menu bar after creating it once in awt?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: menu bar is not appearing

    I do not know. I've never tried.

    Do you have a simple test program to test if it is possible?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    10
    My Mood
    Inspired
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: menu bar is not appearing

    what do java libraries say???
    if there exists a method to do so,i can test easily.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: menu bar is not appearing

    what do java libraries say
    Take a look at the API doc:
    Java Platform SE 7
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    saurabh_kabra (March 29th, 2013)

  8. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    10
    My Mood
    Inspired
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: menu bar is not appearing

    It seems there do not exists a method for that..
    It's available in swing but not in awt..
    that's aweful..
    if anybody else finds ever a method to do so,please let me know.

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: menu bar is not appearing

    Why are you doing anything in AWT?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    10
    My Mood
    Inspired
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: menu bar is not appearing

    Because i am going according to my curriculum of the college and i have only core java,not advance java.But i will move to it after gaining a deep knowledge in core java due to my interest and the features of graphic interface.

Similar Threads

  1. To check presence of padlock icon in the location bar /address bar
    By Rexy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2013, 06:44 AM
  2. [SOLVED] the output is just a blank frame... no menu bar is present.. plz help me out..
    By namita in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 19th, 2012, 01:08 PM
  3. Replies: 2
    Last Post: April 6th, 2012, 01:58 AM
  4. [SOLVED] JFrame Menu bar errors.
    By lorider93p in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2012, 11:02 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

Tags for this Thread