简体   繁体   中英

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)?

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) );

You could also do this:

jScrollPane.setOpaque(false);
jScrollPane.getViewport().setOpaque(false);
jScrollPane.setBorder(null);
jScrollPane.setViewportBorder(null);

jTextArea.setBorder(null);
jTextArea.setBackground(new Color(0, 0, 0, 0));

jscrollpane is the immediate parent component of the jtextarea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM