I'm using a transparent (shaped) JFrame under Java 6 with Mac OS X.
My system tells me that Translucency.PERPIXEL_TRANSLUCENT is supported. Although my system tells me that Translucency.PERPIXEL_TRANSPARENT is not supported, I found out it works under Mac OS X when putting pixels with alpha=0.
Now, when selecting text in the JTextField, it also drags the window as if I would drag on the underlying contentpane.
here my sample code to try (contains main-method to run on your computer)
import com.sun.awt.AWTUtilities;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class DialogTest extends JFrame {
public DialogTest() {
setBackground(new Color(0, 0, 0, 0));
JPanel p1 = new JPanel() {
public void paintComponent(Graphics g1) {
if (g1 instanceof Graphics2D) {
Paint p =
new GradientPaint(0.0f, 0.0f, new Color(240,240,240, 0),
0.0f, getHeight(), new Color(240,240,240, 255), true);
Graphics2D g2d = (Graphics2D) g1;
g2d.setPaint(p);
Shape s = new Ellipse2D.Double(0,0,getWidth(),getHeight());
g2d.fill(s);
}
}
};
add(p1);
p1.setOpaque(false);
p1.add(new JButton("button 1"));
JTextField tf = new JTextField("Sample Text To Select");
p1.add(tf);
p1.add(new JButton("button 2"));
setUndecorated(true);
setSize(400,400);
AWTUtilities.setWindowOpaque(this, false);
}
public static void main(String[] s) {
// Create the GUI on the event-dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DialogTest tw = new DialogTest();
// Display the window.
tw.setVisible(true);
}
});
}
}