Här är ett program som visar hur du kan göra din textarea transparant,
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class GTextArea extends JFrame
{
private TTextArea tt=new TTextArea();
public static void main(String args[])
{
new GTextArea();
}
public GTextArea()
{
this.setSize(250,250);
JPanel pnlMain=new PaintSurface();
pnlMain.setLayout(new BorderLayout());
pnlMain.add(tt,BorderLayout.CENTER);
//pnlMain.add(new JButton("North"),BorderLayout.NORTH);
//pnlMain.add(new JButton("South"),BorderLayout.SOUTH);
//pnlMain.add(new JButton("West"),BorderLayout.WEST);
//pnlMain.add(new JButton("East"),BorderLayout.EAST);
setContentPane(pnlMain);
setVisible(true);
//this.setBackground(Color.GREEN);
}
}
class PaintSurface extends JPanel {
// Since we're always going to fill our entire
// bounds, allow Swing to optimize painting of us
public boolean isOpaque() {
return true;
}
protected void paintComponent(Graphics g) {
// We'll do our own painting, so leave out
// a call to the superclass behavior
// We're telling Swing that we're opaque, and
// we'll honor this by always filling our
// our entire bounds with solid colors.
int w = getWidth();
int h = getHeight();
int leftW = w / 2;
int topH = h / 2;
// Paint the top left and bottom right in red.
g.setColor(Color.RED);
g.fillRect(0, 0, leftW, topH);
g.fillRect(leftW, topH, w - leftW, h - topH);
// Paint the bottom left and top right in white.
g.setColor(Color.WHITE);
g.fillRect(0, topH, leftW, h - topH);
g.fillRect(leftW, 0, w - leftW, topH);
}
}
class TTextArea extends JTextArea
{
int y=0;
Color transcolor;
public TTextArea()
{
super();
this.setOpaque(false);
this.transcolor=new Color(0,0,0,0);
}
public void paintComponent(Graphics g)
{
g.setColor(this.transcolor);
g.fillRect(0,0,getWidth(),getHeight());
super.paintComponent(g);
}
}
Hoppas det är det som du söker :)
Källor:
Unleash Your Creativity with Swing and the Java 2D API
transparency jtextarea
/Viktor