Well we , tipsntricks4all has now come up with a view to create menu buttons in java , menu buttons are nothing but the buttons and when we click on it , a menu with menu items is viewed , this is ofcourse not the latest , but is also available in most of the softwares , in windows explorer also ! But creating them with Java Swing is something new ! here is the program , you will need to know that we do not add buttons , we only use menubar and menu , if you want you can also use toolbar
import javax.swing.*; import java.awt.*; public class menuButtonDemo extends JFrame { // declare variables JMenuBar menuBar; JMenu menu; JMenuItem newFile,open,save,saveAs,print,exit; public menuButtonDemo() { setFrameProperties(); initComponents(); } private void setFrameProperties() { // set frame properties setTitle("Menu Button Demo"); setSize(400,300); setLocation(150,150); setLayout(new FlowLayout()); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } private void initComponents() { // initialize components menuBar=new JMenuBar(); menu=new JMenu("File"); newFile=new JMenuItem("New"); open=new JMenuItem("Open"); save=new JMenuItem("Save"); saveAs=new JMenuItem("Save As"); print=new JMenuItem("Print"); exit=new JMenuItem("Exit"); // add menu items to menu : menu.add(newFile); menu.add(open); menu.add(save); menu.add(saveAs); menu.addSeparator(); menu.add(print); menu.add(exit); // add menu to menu bar : menuBar.add(menu); // add menu bar to frame instead of setJMenuBar : add(menuBar); } public static void main(String args[]) { SwingUtilities.invokeLater(new Runnable(){ public void run() { new menuButtonDemo(); } }); } }