请大家帮帮我!jbuilder菜单问题

kelerfang 2003-06-30 02:30:13
我是刚刚开始学习jbuilder,有个问题,一直搞不懂,我在主窗体上添加了一个菜单控件,也写入了菜单项,但是运行的时候却显示不出来,请问这是怎么回事?
...全文
40 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
kelerfang 2003-06-30
  • 打赏
  • 举报
回复
写了呀,
下面是我随便写的一个frame程序,请过目,是什么问题
package jplafdemo;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/

public class MainFrame extends JFrame {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JMenuBar jMenuBar1 = new JMenuBar();
private JMenu jMenu1 = new JMenu();
private JMenuItem jMenuItem1 = new JMenuItem();
private JMenuItem jMenuItem2 = new JMenuItem();
private JMenuItem jMenuItem3 = new JMenuItem();

private String plafName=UIManager.getCrossPlatformLookAndFeelClassName();
private JButton jButton1 = new JButton();
private JTextField jTextField1 = new JTextField();
private JRadioButton jRadioButton1 = new JRadioButton();
private JCheckBox jCheckBox1 = new JCheckBox();
private JComboBox jComboBox1 = new JComboBox();


//Construct the frame
public MainFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setJMenuBar(jMenuBar1);
this.setSize(new Dimension(423, 183));
this.setTitle("JPlafDemo");
jMenu1.setFont(new java.awt.Font("Dialog", 0, 13));
jMenu1.setText("Plaf");
jMenuItem1.setFont(new java.awt.Font("Dialog", 0, 13));
jMenuItem1.setText("Windows");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem1_actionPerformed(e);
}
});
jMenuItem2.setFont(new java.awt.Font("Dialog", 0, 13));
jMenuItem2.setText("Metal");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem2_actionPerformed(e);
}
});
jMenuItem3.setFont(new java.awt.Font("Dialog", 0, 13));
jMenuItem3.setText("Motif");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuItem3_actionPerformed(e);
}
});
jButton1.setText("jButton1");
jTextField1.setText(this.plafName);
jRadioButton1.setText("jRadioButton1");
jCheckBox1.setText("jCheckBox1");
jMenuBar1.add(jMenu1);
jMenu1.add(jMenuItem1);
jMenu1.add(jMenuItem2);
jMenu1.add(jMenuItem3);
contentPane.add(jTextField1, BorderLayout.SOUTH);
contentPane.add(jRadioButton1, BorderLayout.WEST);
contentPane.add(jCheckBox1, BorderLayout.EAST);
contentPane.add(jComboBox1, BorderLayout.NORTH);
contentPane.add(jButton1, BorderLayout.CENTER);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}

void jMenuItem1_actionPerformed(ActionEvent e) {
this.plafName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try{
UIManager.setLookAndFeel(this.plafName);
SwingUtilities.updateComponentTreeUI(this);
this.pack();
}catch(Exception err){
err.printStackTrace();
}
this.jTextField1.setText(this.plafName);
}

void jMenuItem2_actionPerformed(ActionEvent e) {
this.plafName=UIManager.getCrossPlatformLookAndFeelClassName();
try{
UIManager.setLookAndFeel(this.plafName);
SwingUtilities.updateComponentTreeUI(this);
this.pack();
}catch(Exception err){
err.printStackTrace();
}
this.jTextField1.setText(this.plafName);

}

void jMenuItem3_actionPerformed(ActionEvent e) {
this.plafName="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
try{
UIManager.setLookAndFeel(this.plafName);
SwingUtilities.updateComponentTreeUI(this);
this.pack();
}catch(Exception err){
err.printStackTrace();
}
this.jTextField1.setText(this.plafName);
}
}
hidi7211 2003-06-30
  • 打赏
  • 举报
回复
在jbInit()
加入:this.setMenuBar(MenuBar);

51,407

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧