If you prefer to go lightweight with Swing and you can live without a
title bar, setUndecorated(true) will zap Aqua shadows automagically
for you.
<boo-hoo-hoo>
Oh, those software engineers at Apple, they so cruel, they have no
heart.
Their Java-Cocoa technology is too addictive, like bad heroin. I
cannot
develop on this platform any longer, there's just too much pain...
-sniff-
</boo-hoo-hoo>
- Craig
/**
Transparent Swing window for Mac OS X.
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class TransFrame extends JFrame
{
/////////////////
// Constructor //
/////////////////
public TransFrame()
{
super("Transparent Frame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(new Dimension(400,300));
setBackground(new Color(0f, 1f ,0f, 0.0f)); // Transparent
// setBackground(new Color(0f, 1f ,0f, 0.5f)); // Transparent 50%
green
// setBackground(new Color(0f, 1f, 0f, 1.0f)); // Opaque
setUndecorated(true); // Zap title bar & shadows
final JButton b1 = new JButton("Thing One");
b1.setOpaque(true);
b1.setBackground(Color.blue);
b1.setForeground(Color.white);
// b1.setContentAreaFilled(false);
b1.setBorderPainted(false);
b1.setFocusPainted(false);
final JButton b2 = new JButton("Thing Two");
b2.setOpaque(true);
b2.setBackground(Color.red);
b2.setForeground(Color.white);
// b2.setContentAreaFilled(false);
b2.setBorderPainted(false);
b2.setFocusPainted(false);
final JPanel p = new JPanel(new GridLayout(2,1, 10,10));
p.setOpaque(false);
p.add(b1);
p.add(b2);
final JPanel cp = new JPanel(new BorderLayout());
cp.setOpaque(false);
cp.setBorder(BorderFactory.createEmptyBorder(36,36,36,36));
cp.add(p, BorderLayout.CENTER);
setContentPane(cp);
}
public static void main(final String args[])
{
final TransFrame f = new TransFrame();
SwingUtilities.invokeLater
(
new Runnable()
{
public void run()
{
f.setVisible(true);
}
}
);
}
}