- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a Vertical menu bar in Java?
Let us create a MenuBar −
JMenuBar menuBar = new JMenuBar();
Now, set its layout to create a Vertical Menu Bar with GridLayout −
menuBar.setLayout(new GridLayout(0,1));
The following is an example to create a Vertical menu bar in Java −
Example
package my; import java.awt.GridLayout; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class SwingDemo { public static void main(final String args[]) { JFrame frame = new JFrame("MenuBar Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); menuBar.setLayout(new GridLayout(0,1)); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu); JMenuItem menuItem1 = new JMenuItem("New", KeyEvent.VK_N); fileMenu.add(menuItem1); JMenuItem menuItem2 = new JMenuItem("Open File", KeyEvent.VK_O); fileMenu.add(menuItem2); JMenu editMenu = new JMenu("Edit"); editMenu.setMnemonic(KeyEvent.VK_E); menuBar.add(editMenu); JMenuItem menuItem3 = new JMenuItem("Cut", KeyEvent.VK_C); editMenu.add(menuItem3); JMenu sourceMenu = new JMenu("Source"); sourceMenu.setMnemonic(KeyEvent.VK_S); menuBar.add(sourceMenu); JMenu refactorMenu = new JMenu("Refactor"); refactorMenu.setMnemonic(KeyEvent.VK_R); menuBar.add(refactorMenu); JMenu navigateMenu = new JMenu("Navigate"); navigateMenu.setMnemonic(KeyEvent.VK_A); menuBar.add(navigateMenu); menuBar.revalidate(); frame.setJMenuBar(menuBar); frame.setSize(550, 350); frame.setVisible(true); } }
This will produce the following output −
- Related Articles
- How to create a vertical menu with CSS?
- How to right-align a menu in the menu bar with Java?
- How to create Vertical progress bar occupying the entire frame in Java
- How to create a vertical tab menu with CSS and JavaScript?
- How to create a mega menu (full-width dropdown menu in a navigation bar) with HTML and CSS?
- How to create a vertical toolbar in Java?
- How to create a Vertical Navigation Bar using HTML and CSS ?
- How to create a submenu for a Menu in Java
- How to create a stacked bar plot with vertical bars in R using ggplot2?
- Java Program to create a vertical ProgressBar
- How to create a User Menu in PowerShell?
- How to create a Popup Menu in Tkinter?
- How to create vertical button column with GridLayout in Java?
- How can we create a JPopupMenu with a sub menu in Java?
- How to create a Menu using JavaFX?

Advertisements