我在运行Mavericks的Mac上使用Eclipse,但这应该不是问题。我似乎没有做错任何事情,即使在尝试JMenuBar
和JFrame
之后,我也无法让repaint()
显示在revalidate()
上,这是代码和图片出现的灰线...
创建JFrame ..(此对象在驱动程序中的Runnable(run())中创建)
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);
}
,那么在框架顶部栏下面的那条小灰线就会消失
答案 0 :(得分:2)
您尚未向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);