如何添加图片?

时间:2015-04-12 07:03:11

标签: java

我尝试在按钮中添加图片ImageIcon给我错误,我也导入java.awt.Image;。但是静止图像没有上传,我现在该怎么办?

JButton btnFind = new JButton("Find");
    Image img = new ImageIcon(this.getClass().getResource("/search.png")).getImage();
    btnFind.setIcon(new ImageIcon(img)); 
    btnFind.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        }
    });
    btnFind.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent arg0) {
            try {
                 cDriver.fObjectWithDataCity_V3(textFieldSearch.getText());
                 fDataInTextBoxes();



                } catch (Exception ee) {
                    // TODO Auto-generated catch block
                    ee.printStackTrace();
                }

1 个答案:

答案 0 :(得分:0)

您还需要导入

import javax.swing.ImageIcon;