Reputation: 2527
my JMenuBar is not showing AT ALL. This is just a barebones GUI. I have sat here for quite a while now, and I cannot see the problem, soo, as they say, four eyes are better than two.
Thanks.
import javax.swing.*;
import java.awt.*;
public class MainGui{
private DrawPanel drawPanel;
private JFrame mainFrame;
private JPanel drawPanel;
private JMenuBar menuBar;
private JMenu fileMenu, imgMenu, helpMenu;
private JMenuItem fileNew, fileOpen, fileSave, fileExit;
private JMenuItem imgBtn1;
private JMenuItem hlpAbout;
public MainGui(DrawPanel drawPanel){
mainFrame = new JFrame("JDraw v1");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setLayout(new BorderLayout());
this.drawPanel = drawPanel;
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
imgMenu = new JMenu("Image");
helpMenu = new JMenu("Help");
fileNew = new JMenuItem("New File");
fileOpen = new JMenuItem("Open File");
fileSave = new JMenuItem("Save File");
fileExit = new JMenuItem("Exit");
imgBtn1 = new JMenuItem("Useless Button");
hlpAbout = new JMenuItem("About this program");
mainFrame.add(menuBar, BorderLayout.PAGE_START);
menuBar.add(fileMenu);
menuBar.add(imgMenu);
menuBar.add(hlpMenu);
fileMenu.add(fileNew);
fileMenu.add(fileOpen);
fileMenu.add(fileSave);
fileMenu.add(fileExit);
imgMenu.add(imgBtn1);
helpMenu.add(hlpAbout);
mainFrame.add(drawPanel, BorderLayout.CENTER);
mainFrame.pack();
mainFrame.setSize(640,480);
mainFrame.setResizable(false);
mainFrame.setVisible(true);
}
}
Upvotes: 1
Views: 5017
Reputation: 40811
You want to do:
mainFrame.setJMenuBar(menuBar);
not:
mainFrame.add(menuBar, BorderLayout.PAGE_START);
Upvotes: 6