You haven't add anything to the JMenuBar
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
editMenu = new JMenu("Edit");
helpMenu = new JMenu("Help");
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(helpMenu);
Вопрос
I'm using Eclipse on a Mac running Mavericks, but that shouldn't be the problem. I seem to be doing nothing wrong, I just can't get this JMenuBar
to show up on my JFrame
even after trying repaint()
and revalidate()
, here's the code and picture of the grey line that is showing up..
create the JFrame.. (this object is created in a Runnable(run()) in the driver)
public GUIPhotoAlbum ()
{
super("PhotoAlbum");
usersAlbum = new PhotoAlbum();
setIcon();
this.setSize(875, 625);
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout(5, 5));
initComponents();
initMenuBar();
repaint();
revalidate();
initTopPanel();
add(topPanel, BorderLayout.CENTER);
initBottomPanel();
add(bottomPanel, BorderLayout.SOUTH);
addListeners();
setLocationRelativeTo(null);
setVisible(true);
}
initMenuBar():
private void initMenuBar()
{
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
editMenu = new JMenu("Edit");
helpMenu = new JMenu("Help");
openItem = new JMenuItem("Open");
saveItem = new JMenuItem("Save");
exitItem = new JMenuItem("Exit");
addItem = new JMenuItem("Add");
modifyItem = new JMenuItem("Modify");
deleteItem = new JMenuItem("Delete");
aboutItem = new JMenuItem("About ...");
fileMenu.add(openItem);
fileMenu.add(saveItem);
fileMenu.add(exitItem);
editMenu.add(addItem);
editMenu.add(modifyItem);
editMenu.add(deleteItem);
helpMenu.add(aboutItem);
//sets the menu bar for the JFrame
this.setJMenuBar(menuBar);
}
Here's my JFrame window so far:
..That tiny grey line just below the top bar of frame goes away if you take out this.setJMenuBar(menuBar)
from code
Решение
You haven't add anything to the JMenuBar
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
editMenu = new JMenu("Edit");
helpMenu = new JMenu("Help");
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(helpMenu);