这个是画在JTextPane里的例子,你修改一下=====================================================================import javax.swing.JFrame;
import javax.swing.JTextPane;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JScrollPane;
import javax.swing.ImageIcon;
import java.net.URL;
import java.awt.Image;
import java.awt.Graphics;
import java.net.MalformedURLException;public class Test {
private JFrame frame;
private JTextPane textP;
private JScrollPane sPan;
private ImageIcon imageIcon; public Test() {
jbInit();
} public void jbInit() {
frame = new JFrame("给JTextPane加入底图");
String url="http://www.csdn.net/images/Homeother/BTS2004.JPG";
try {
imageIcon = new ImageIcon(new URL(url));
}
catch (MalformedURLException ex) {
}
textP = new JTextPane(){
Image image = imageIcon.getImage();
{setOpaque(false);}
public void paintComponent (Graphics g) {
g.drawImage(image, 0, 0, this);
super.paintComponent(g);
} };
sPan = new JScrollPane(textP);
frame.getContentPane().add(sPan); frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(230, 160);
frame.setVisible(true);
} public static void main(String[] args) {
new Test();
}
}
import javax.swing.JTextPane;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JScrollPane;
import javax.swing.ImageIcon;
import java.net.URL;
import java.awt.Image;
import java.awt.Graphics;
import java.net.MalformedURLException;public class Test {
private JFrame frame;
private JTextPane textP;
private JScrollPane sPan;
private ImageIcon imageIcon; public Test() {
jbInit();
} public void jbInit() {
frame = new JFrame("给JTextPane加入底图");
String url="http://www.csdn.net/images/Homeother/BTS2004.JPG";
try {
imageIcon = new ImageIcon(new URL(url));
}
catch (MalformedURLException ex) {
}
textP = new JTextPane(){
Image image = imageIcon.getImage();
{setOpaque(false);}
public void paintComponent (Graphics g) {
g.drawImage(image, 0, 0, this);
super.paintComponent(g);
} };
sPan = new JScrollPane(textP);
frame.getContentPane().add(sPan); frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(230, 160);
frame.setVisible(true);
} public static void main(String[] args) {
new Test();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货