4

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. 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));
Zoe
  • 27,060
  • 21
  • 118
  • 148
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287

2 Answers2

4

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);
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

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
  • 1,243
  • 9
  • 9