0

-I am trying to display GUI with menubar containing menus like "Open","Run","Help" but all I am able to see in GUI is menu "File"

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.miginfocom.swing.MigLayout;

public class test11 extends JFrame {   
   public test11(String title, int width, int height) {

        //setting up frame
        setTitle(title);
        setSize(width, height);        
        setLocationRelativeTo(null);
        setMinimumSize(new Dimension(700, 500));
        setVisible(true);
        setLayout(new MigLayout("debug, fillx, gap unrel rel","[grow, fill][fill]","[fill][fill]"));//no idea

        //Menubar       
        JMenuBar m = new JMenuBar();
        m.setBackground(new Color(192,192,192));

        JMenu op = new JMenu("Open");
        op.add(new JMenuItem("Catalogue"));
        op.add(new JMenuItem("Read a Paper!"));
        JMenuItem find = new JMenuItem("Find...");
        find.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK));  
        op.add(find);
        JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_E);
        exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.ALT_MASK));
        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        op.add(exit);

        JMenu run = new JMenu("Run");
        run.add(new JMenuItem("Search My System"));  
        JMenuItem synchr = new JMenuItem("Start Synchronizer", 'S');   
        synchr.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));  
        run.add(synchr);

        JMenu help = new JMenu("Help");     
        JMenuItem h = new JMenuItem("Help Contents", 'H');   
        h.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK));  
        help.add(h);
        help.add(new JMenuItem("Keyboard Shortcut Card"));
        help.add(new JMenuItem("About Application"));        

        m.add(op);
        m.add(run);
        m.add(help);        
        setJMenuBar(m);  

        //Toolbar
        JToolBar toolBar = new JToolBar("Draggable");
        JButton subject = new JButton("Subject");
        toolBar.add(subject);
        add(toolBar, "span, height 20:35:50, wrap");

        JPanel table = new JPanel();
        JPanel sideBar = new JPanel();
        add(table, "width 400:600:, dock center, growy");
        add(sideBar, "width 250:300:350, dock west, growy");    
    }

    public static void main(String args[]){
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new test1("ResearchSoft",1300,700).setVisible(true);
            }
        });
    }
}

-Even changed toolbar button to "Subject" but it displays "Select"

Could anyone find out why this strange behavior happening?

  • nothing are strange. You are doing the changes in test11 but you are creating the object of test1. Due to that you are not looking the change made. – Rahul Feb 24 '14 at 13:01

1 Answers1

2

You have created the object of

 new test1("ResearchSoft",1300,700).setVisible(true);

but you want to create the object of

new test11("ResearchSoft",1300,700).setVisible(true);
Rahul
  • 3,479
  • 3
  • 16
  • 28