Java tutorial
import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JTextPane; public class Main { public static void main(String[] args) { JFrame frame = new JFrame(); MyTextPane textPane = new MyTextPane(); frame.add(textPane); frame.pack(); frame.setVisible(true); } } class MyTextPane extends JTextPane { public MyTextPane() { super(); setText("Hello World"); setOpaque(false); setBackground(new Color(0, 0, 0, 0)); } @Override protected void paintComponent(Graphics g) { g.setColor(Color.GREEN); g.fillRect(0, 0, getWidth(), getHeight()); // uncomment the following to draw an image // Image img = ...; // g.drawImage(img, 0, 0, this); super.paintComponent(g); } }