I'd like to add a bacground image to JTextArea. Haw can I do that?
Printable View
I'd like to add a bacground image to JTextArea. Haw can I do that?
Code:public final class AreaTest extends JFrame
{
public AreaTest(final Image image)
{
Container container = getContentPane();
container.setLayout(new BorderLayout());
JTextArea textArea = new JTextArea()
{
//Image grayImage = GrayFilter.createDisabledImage(image);
{setOpaque(false);}
public void paintComponent (Graphics g)
{
g.drawImage(image, 0, 0, (int)getSize().getWidth(), (int)getSize().getHeight(), this);
//g.drawImage(grayImage, 0, 0, (int)getSize().getWidth(), (int)getSize().getHeight(), this);
super.paintComponent(g);
}
};
container.add(textArea);
}
public static void main(String[] args)
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.createImage("bg.jpg");
AreaTest areaTest = new AreaTest(image);
areaTest.setSize(300, 300);
//areaTest.setResizable(false);
areaTest.setTitle("Area test");
areaTest.setVisible(true);
}
}