Search code examples
javaswingapplettransparentjtextarea

Java: Transparent TextArea + draw background


My question here is fairly simple. Can JTextArea's be set to transparent, but not completely invisible? Also, if it's possible, how can I draw an image behind it (draw the image first, and then draw the transparent text area overtop of it)?


Solution

  • 1) Override the paintComponent() method of the JTextArea something like:

    g.drawImage(...);
    super.paintComponent(g);
    

    2) When you create the text area you will need to give it a transparent background:

    setBackground( new Color(r, g, b, alpha) );