Java Swing JMenuBar
我的 JMenuBar 根本不显示。这只是一个准系统 GUI。我已经在这里坐了很长一段时间了,但我看不出问题所在,所以,正如他们所说,四只眼睛比两只眼睛好。
谢谢。
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);
}
}
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想做:
不:
You want to do:
not:
我认为你应该使用:
I think you should use: