给JTextAear添加背景图片
2015-09-20 19:58
302 查看
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JTextArea;
//重写JTextArea的绘画方法paint(Graphics g)
public class JTextAreaWithIcon extends JTextArea
{
private static final long serialVersionUID = 1L;
private Image image;
/**
* 带有参数的构造函数
* @param ximageIcon 要添加的背景图片
*/
public JTextAreaWithIcon( ImageIcon ximageIcon)
{
ImageIcon imageIcon = ximageIcon;
this.image = imageIcon.getImage();
setOpaque(false);
}
/**
* 无参构造,即不设置背景图
*/
public JTextAreaWithIcon( )
{
ImageIcon imageIcon = new ImageIcon();
this.image = imageIcon.getImage();
setOpaque(false);
}
/**
* Overriding 重写方法
*/
public void paint(Graphics g)
{
g.drawImage(image, 0, 0, this);
super.paint(g);
}
}
/***用这个类来代替JTextArea实例化就ok了***/
jTextArea1 = new JTextAreaWithIcon(new ImageIcon("C:\\Users\\Lavee\\Desktop\\icon\\welcomeall.jpg"));
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JTextArea;
//重写JTextArea的绘画方法paint(Graphics g)
public class JTextAreaWithIcon extends JTextArea
{
private static final long serialVersionUID = 1L;
private Image image;
/**
* 带有参数的构造函数
* @param ximageIcon 要添加的背景图片
*/
public JTextAreaWithIcon( ImageIcon ximageIcon)
{
ImageIcon imageIcon = ximageIcon;
this.image = imageIcon.getImage();
setOpaque(false);
}
/**
* 无参构造,即不设置背景图
*/
public JTextAreaWithIcon( )
{
ImageIcon imageIcon = new ImageIcon();
this.image = imageIcon.getImage();
setOpaque(false);
}
/**
* Overriding 重写方法
*/
public void paint(Graphics g)
{
g.drawImage(image, 0, 0, this);
super.paint(g);
}
}
/***用这个类来代替JTextArea实例化就ok了***/
jTextArea1 = new JTextAreaWithIcon(new ImageIcon("C:\\Users\\Lavee\\Desktop\\icon\\welcomeall.jpg"));
相关文章推荐
- 测试用例要素
- .NET重思(二)接口和抽象类的取舍
- mybatis返回对象包含Long类型主键值 oracle数据库
- k merge算法
- 网上看到的一道腾讯面试题
- 软工实践---个人
- document.body.scrollTop 值总为0
- 第16本:《视觉繁美:信息可视化方法与案例解析》
- 第14本:《李鸿章传》
- 第10本:《设计心理学》
- C++中虚析构函数
- java SE复习笔记25
- 第16本:《视觉繁美:信息可视化方法与案例解析》
- 第14本:《李鸿章传》
- 第10本:《设计心理学》
- 第17本:《代码的未来》
- lamp介绍,wordpress,phpmyadmin,discuzz安装
- Ubuntu 中 设置 FireFox 豆沙绿
- java 在jtextarea(文本框)里显示拖动进来文件的路径
- xcode6中添加pch全局引用文件