java 中的JPanel插入背景图片和按钮的问题

2024-12-22 09:43:23
推荐回答(1个)
回答1:

重写JPanel的paintComponent方法:
JPanel jp = new JPanel() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
ImageIcon img = new ImageIcon("xxx.jpg");
g.drawImage(img.getImage(), 0, 0, null);
}
};