views:

63

answers:

2

Hi,

I just met the utilities (com.sun.awt.AWTUtilities) to make your JFrame really transparent. Documentation here. This works very good. Even in Linux with the desktop effects with wobbly windows turned on (Here a little video)! But I want to make also a non-transparent component on the transparent JFrame.

Does anyone know, if this is possible, how?

Here is the code I used:

import com.sun.awt.AWTUtilities;

/* "this" is the JFrame */
this.setUndecorated(true);
AWTUtilities.setWindowOpaque(this, true);
AWTUtilities.setWindowOpacity(this, 0.5f);
AWTUtilities.setWindowShape(this, new RoundRectangle2D.Float(0f, 0f, (float) getWidth(), (float) getHeight(), 15f, 15f));

Thanks

A: 

IIUC, Translucent Windows applies to the entire java.awt.Window and contents, but you might try the approach shown below and in this example.

JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setBackground(new Color(0f, 0f, 0f, 0.1f));
f.setUndecorated(true);
f.add(new JLabel("<html>Testing<br>1, 2, 3</html>"));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
trashgod
This doesn't work in Linux... On mac, this is the solution for my problem... Sad...
Martijn Courteaux
@Martijn Courteaux: Well, neither does the `AWTUtilities` demo: "Note that the effects may not be supported by the underlying platform..."
trashgod
+1  A: 

What you want to do is setWindowOpaque to false and draw the background with low alpha (or 0 alpha if you want complete transparency). The components will still be drawn opaque. See this article and look at per-pixel translucency.

qmega