You are on page 1of 3

Adding Menus to and Removing Menus From Menu Bars : JMenuBar Swing Java Tutorial

Home Java Tutorial


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. Language Data Type Operators Statement Control Class Definition Development Reflection Regular Expressions Collections Thread File Generics I18N Swing Swing Event 2D Graphics SWT SWT 2D Graphics Network Database Hibernate JPA JSP JSTL Servlet Web Services SOA EJB3 Spring PDF Email J2ME J2EE Application XML

Java Tutorial Swing JMenuBar

Search

14.22.2.Adding Menus to and Removing Menus From Menu Bars


Previous/Next
If you do add or remove menus, you must then revalidate() the menu bar to display the changes.

import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; public class AddingRemovingJMenu { public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar();
Are you a developer? Try out the HTML to PDF API

open in browser PRO version

pdfcrowd.com

33. 34. 35. 36. 37. 38. 39.

XML Design Pattern Log Security Apache Common Ant JUnit

// File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu); JMenu editMenu = new JMenu("Edit"); menuBar.add(editMenu); menuBar.remove(0); menuBar.revalidate(); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); } }

14.22.JMenuBar 14.22.1. 14.22.2. 14.22.3.


open in browser PRO version

Creating JMenuBar Components Adding Menus to and Removing Menus From Menu Bars Menu Accelerator
pdfcrowd.com

Are you a developer? Try out the HTML to PDF API

14.22.4. 14.22.5. 14.22.6. 14.22.7.

Vertical menu bar Shows how to right-align a menu in the menu bar, using a glue component Customize menu layout by changing the menu bar to use a top-tobottom box layout, and the popup menu to use a left-to-right box layout Customizing JMenuBar Look and Feel java2s.com | Contact Us | Privacy Policy Copyright 2009 - 12 Demo Source and Support. All rights reserved. All other trademarks are property of their respective owners.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You might also like