怎么在下拉菜单上添加入图片呢, 请各路英雄指教!
或者帮我在代码里加入.谢谢!import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
public class NewJFrame extends javax.swing.JFrame {
private JMenuBar jMenuBar1;
private JMenu jMenu1;
private JMenuItem jMenuItem1;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
NewJFrame inst = new NewJFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}

public NewJFrame() {
super();
initGUI();
}

private void initGUI() {
try {
javax.swing.UIManager.setLookAndFeel("org.fife.plaf.Office2003.Office2003LookAndFeel");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
JMenuBar menuBar = new JMenuBar();
JMenu file = new JMenu("系统");

JMenuItem databak = new JMenuItem("数据备份");

JMenuItem datapurview = new JMenuItem("数据权限");



setJMenuBar(menuBar);
menuBar.add(file);
file.add(databak);
file.add(datapurview);



}
pack();

setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}}

解决方案 »

  1.   

    使用下面的试试!ClassLoader cl = getClass().getClassLoader();
    URL backup = cl.getResource("org/fife/plaf/OfficeXP/copy.gif");
    URL right = cl.getResource("org/fife/plaf/OfficeXP/cut.gif");
    JMenuItem databak = new JMenuItem("数据备份", new ImageIcon(backup));
    JMenuItem datapurview = new JMenuItem("数据权限",new ImageIcon(right));
      

  2.   

    JMenuItem(String text, Icon icon) 
              创建带有指定文本和图标的 JMenuItem。给你的后面加一个参数就好.
      

  3.   

    楼上的提示其实都已经够了 先把问题集中 试核心功能
    JMenuItem databak = new JMenuItem("数据备份", new ImageIcon("xxx.jpg"));
    图片放当前工程根目录
      

  4.   

    利用你的代码加几句就可以了呀import java.net.URL;import javax.swing.ImageIcon;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.SwingUtilities;
    import javax.swing.WindowConstants;public class NewJFrame extends javax.swing.JFrame {
    private JMenuBar jMenuBar1;
    private JMenu jMenu1;
    private JMenuItem jMenuItem1; public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    NewJFrame inst = new NewJFrame();
    inst.setLocationRelativeTo(null);
    inst.setVisible(true);
    }
    });
    } public NewJFrame() {
    super();
    initGUI();
    } private void initGUI() {
    try {
    javax.swing.UIManager
    .setLookAndFeel("org.fife.plaf.Office2003.Office2003LookAndFeel");
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    {
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu("系统"); ClassLoader cl = getClass().getClassLoader();
    URL backup = cl.getResource("org/fife/plaf/Office2003/open.gif");
    URL right = cl.getResource("org/fife/plaf/Office2003/cut.gif");
    JMenuItem databak = new JMenuItem("数据备份", new ImageIcon(backup));
    JMenuItem datapurview = new JMenuItem("数据权限", new ImageIcon(
    right)); setJMenuBar(menuBar);
    menuBar.add(file);
    file.add(databak);
    file.add(datapurview);
    }
    pack(); setSize(400, 300);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }}
      

  5.   

    Java code
    import java.net.URL;import javax.swing.ImageIcon;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.SwingUtilities;
    import javax.swing.WindowConstants;public class NewJFrame extends javax.swing.JFrame {
        private JMenuBar jMenuBar1;
        private JMenu jMenu1;
        private JMenuItem jMenuItem1;    public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    NewJFrame inst = new NewJFrame();
                    inst.setLocationRelativeTo(null);
                    inst.setVisible(true);
                }
            });
        }    public NewJFrame() {
            super();
            initGUI();
        }    private void initGUI() {
            try {
                javax.swing.UIManager
                        .setLookAndFeel("org.fife.plaf.Office2003.Office2003LookAndFeel");
                setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                {
                    JMenuBar menuBar = new JMenuBar();
                    JMenu file = new JMenu("系统");                ClassLoader cl = getClass().getClassLoader();
                    URL backup = cl.getResource("org/fife/plaf/Office2003/open.gif");
                    URL right = cl.getResource("org/fife/plaf/Office2003/cut.gif");
                    JMenuItem databak = new JMenuItem("数据备份", new ImageIcon(backup));
                    JMenuItem datapurview = new JMenuItem("数据权限", new ImageIcon(
                            right));                setJMenuBar(menuBar);
                    menuBar.add(file);
                    file.add(databak);
                    file.add(datapurview);
                }
                pack();            setSize(400, 300);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }}