Java 如何添加图像?
我试图在按钮中添加图像此Java 如何添加图像?,java,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.addAct
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();
}
您还需要导入
import javax.swing.ImageIcon;
谢谢,问题解决了。因为我不导入javax.swing.ImageIcon;创建一个自定义组件,可能基于JPanel,重写paintComponent方法并在其中绘制图像请不要使用注释询问后续问题。您能告诉我如何在java gui中添加背景图像吗form@AhmedAbbas相关的