将JEditorPane透明就可以看到下面组件上绘的图了。import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;public class Test extends JFrame {
JPanel pane;
JEditorPane text;
Image image; public Test() {
super("背景");
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
System.exit(0);
}
});
String url = "http://images.csdn.net/20041202/sms3.JPG";
try {
image = (new ImageIcon(new URL(url))).getImage();
text = new JEditorPane();
text.setOpaque(false);
pane = new JPanel() {
public void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, this);
}
};
pane.setLayout(new BorderLayout());
pane.add(text);
}
catch (MalformedURLException ex) {
}
this.getContentPane().add(pane);
this.setSize(200, 150);
this.setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}
import java.awt.*;
import java.awt.event.*;
import java.net.*;public class Test extends JFrame {
JPanel pane;
JEditorPane text;
Image image; public Test() {
super("背景");
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
System.exit(0);
}
});
String url = "http://images.csdn.net/20041202/sms3.JPG";
try {
image = (new ImageIcon(new URL(url))).getImage();
text = new JEditorPane();
text.setOpaque(false);
pane = new JPanel() {
public void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, this);
}
};
pane.setLayout(new BorderLayout());
pane.add(text);
}
catch (MalformedURLException ex) {
}
this.getContentPane().add(pane);
this.setSize(200, 150);
this.setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货