[内力深厚者入]请问,如何实现在JTextPane中载入背景图,并且可以在图上添加文字 不说具体怎么做,只告诉你怎么去模仿;首先得对awt和swing有透彻的理解;然后,反编译永中office,看看他里面的大量界面控件是如何实现的(由于永中使用了极强的混码技术,这个比较费事)。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不要用上面,你会走火入魔。不如直接研究一下 swing 的源码还有,可能你想复杂了,如果是我的话会先试试 在文本框后面插一张图片 然后设置它背景透明 试试这个. public void paintComponent(Graphics g) { Insets insets = getInsets(); icon.paintIcon(this, g, insets.left, insets.top); super.paintComponent(g); } 这个……和我的方法只在super的调用上调换了位置啊…… -0- 试了。icon.paintIcon(this, g, insets.left, insets.top);super.paintComponent(g); 这样的顺序是可以显示文字但是图片显示不了super.paintComponent(g); icon.paintIcon(this, g, insets.left, insets.top);这样的顺序是可以显示文字但是图片显示不了-0- 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(); }}<------ 树欲静而风不止 ------> 太感谢了!!!!!!!!!!!!!!!!!!100分送给楼上的了给大家看看我正在设计的东东 ^0^TRPGzone用来玩AD&D游戏的网络聊天工具~http://www.impk.net/marquis/TRPGzone/TRPGchat%20v0.1.6.jpg java用jna调用C的时候怎么获取C中输出参数的值 Applet如何向服务器的指定目录传递文件 急!!文件目录重命名问题 有哪位大虾有关于java的基础题目呀! 一个关于ArrayIndexOutOfBoundsException的错误 HttpClient post 关于post数据为中文的问题 一个关于在程序里动态编译执行程序的问题。。。 如何获得一个(20~30)之间的随机数. 请教:哪位做过基于CORBA的程序 Java中父类引用转化为子类引用 一个关于import的奇怪的问题 问个菜鸟问题:为什么eclipse不用安装直接点击eclipse.exe就可以用啊?
还有,可能你想复杂了,如果是我的话会先试试 在文本框后面插一张图片 然后设置它背景透明
public void paintComponent(Graphics g)
{
Insets insets = getInsets();
icon.paintIcon(this, g, insets.left, insets.top);
super.paintComponent(g);
}
icon.paintIcon(this, g, insets.left, insets.top);
super.paintComponent(g);
这样的顺序是可以显示文字但是图片显示不了super.paintComponent(g);
icon.paintIcon(this, g, insets.left, insets.top);
这样的顺序是可以显示文字但是图片显示不了-0-
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();
}
}
<------ 树欲静而风不止 ------>