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 开发者_JAVA技巧a javax.swing.JInternalFrame
or javax.swing.JButton
.
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();
}
}
精彩评论