自定义JPanel类: import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JPanel; public class BackgroundPanel extends JPanel { public BackgroundPanel() { } public void paintComponent(Graphics g) { int x = 0, y = 0; java.net.URL imgURL = getClass().getResource("/pic/login.jpg"); // /pic/login.jpg是测试图片,与BackgroundPanel.java放在同一目录下 ImageIcon icon = new ImageIcon(imgURL); g.drawImage(icon.getImage(), x, y, getSize().width, getSize().height, this); while (true) { g.drawImage(icon.getImage(), x, y, this); if (x > getSize().width && y > getSize().height) break; // 这段代码是为了保证在窗口大于图片时,图片仍能覆盖整个窗口 if (x > getSize().width) { x = 0; y += icon.getIconHeight(); } else x += icon.getIconWidth(); } } } 最后在窗体中引用: login_panel = new BackgroundPanel();