I've been using the new com.sun.awt.AWTUtilities
class and am intrigued. I got com.sun.awt.AWTUtilities/setWindowOpacity(java.awt.Window window, float f)
to work perfectly, but am now wondering if there is any way to change the opacity of an individual component, such as a javax.swing.JInternalFrame
or javax.swing.JButton
.
Asked
Active
Viewed 452 times
2

Ky -
- 30,724
- 51
- 192
- 308
1 Answers
1
Try this:
class TransparentButton extends JButton {
public TransparentButton(String text) {
super(text);
setOpaque(false);
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
super.paint(g2);
g2.dispose();
}
}
-
will this work if I have customized my buttons' border, background,a and foreground, already? – Ky - Nov 15 '10 at 03:42
-
So far as I know it should. The only way to know for sure is to test it out though. – Nov 15 '10 at 03:43