Try calling setOpaque(false) in the constructor of your class that extends JTextArea. Having opaque set to true causes the JTextArea's color background and text to show.
package demo;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class BackgroundDemo extends JFrame{
public BackgroundDemo() {
initUI();
}
public void initUI() {
MyTextArea area = new MyTextArea();
add(area);
area.setText("Demo Text");
pack();
setSize(400, 400);
}
public static void main(String[] args) {
BackgroundDemo demo = new BackgroundDemo();
demo.setVisible(true);
}
}
class MyTextArea extends JTextArea {
public MyTextArea() {
setOpaque(false);
setVisible(true);
setPreferredSize(new Dimension(400, 400));
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
try {
BufferedImage image = ImageIO.read(BackgroundDemo.class.getResource("/demo/background.png"));
g.drawImage(image, 0, 0, this);
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}