final File f = new File("C:\\abc.txt");
final String txt = URLFileSystem.getContents(f);
final JFrame frame = new JFrame("文件内容");
frame.setLayout(new BorderLayout());
frame.setIconImage(new ImageIcon("D:\\images\\fastpath24.png").getImage());
final JMenuBar MenuBar = new JMenuBar();
//final JToolBar topToolbar1 = new JToolBar();
frame.setJMenuBar(MenuBar);
//frame.getContentPane().add(topToolbar1, BorderLayout.NORTH);
final JMenu file = new JMenu(); final JMenuItem newfile = new JMenuItem();
newfile.setText("新建"); final JMenuItem open = new JMenuItem();
newfile.setText("打开");
file.add(newfile);
file.add(open);
MenuBar.add(file);
final JTextPane pane = new JTextPane();
pane.setBackground(Color.white);
pane.setFont(new Font("Dialog",Font.PLAIN,12));
pane.setEditable(false);
pane.setText(txt);
frame.add(new JScrollPane(pane),BorderLayout.CENTER);
frame.pack();
frame.setSize(600,500);
GraphicUtils.centerWindowOnScreen(frame);
frame.setVisible(true);
可是结果如下图所示:第一:跟本看不见JMenuBar,但有确实存在,用鼠标单击左上角相应区域也会弹出菜单来
第二:当file菜单中有两个以上选项时,只显示最后添加的那个选项,比如程序中只显示“打开”选项望大家指教!
解决方案 »
- java中有关date类的问题
- 接口的访问权限默认是public还是包内?还是接口的访问权限只能是public,不能是包内?
- 关于数据库查询数据对象序列化问题!急!非常感谢!
- Linux下运行eclipse出错(JVM terminated. Exit code=6)
- dom4j解析xml文件报java.lang.NullPointerException Nested 这样的错误
- java中有没有类似于VB中Msgbox的对话框函数?
- 不知道怎样写这个正则表达式???
- java与C的Socket通信问题,紧急求助!
- 搞java安全者请进或搞安全者
- 新学JAVA,运行程序为什么都抛出如下的异常???
- Java 运行不了,出现"Error: could not find java.dll" 怎么解决?
- win7卸载jdk时windows installer安装包有问题
这句有问题呢?
--------->改为
frame.getContentPane().add("North",MenuBar);效果是一样
newfile.setText("新建"); final JMenuItem open = new JMenuItem();
newfile.setText("打开");
把newfile.setText("打开");改为
open.setText("打开");即可求解问题一!!!
添加 file.setText("文件");
就可以了2、另一个问题,楼上已经说了