这是一个在Jframe中添加背景图像的简单示例:
import javax.swing.*;import java.awt.*;import java.awt.event.*;class BackgroundImageJframe extends Jframe{ JButton b1; JLabel l1; public BackgroundImageJframe() { setTitle("Background Color for Jframe"); setSize(400,400); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); // Another way setLayout(new BorderLayout()); setContentPane(new JLabel(new ImageIcon("C:\Users\Computer\Downloads\colorful design.png"))); setLayout(new FlowLayout()); l1=new JLabel("Here is a button"); b1=new JButton("I am a button"); add(l1); add(b1); // Just for refresh :) Not optional! setSize(399,399); setSize(400,400); } public static void main(String args[]) { new BackgroundImageJframe(); }}- 点击这里了解更多信息



