2

我一直在使用新com.sun.awt.AWTUtilities课程并且很感兴趣。我必须com.sun.awt.AWTUtilities/setWindowOpacity(java.awt.Window window, float f)完美地工作,但现在想知道是否有任何方法可以更改单个组件的不透明度,例如 ajavax.swing.JInternalFramejavax.swing.JButton.

4

1 回答 1

1

尝试这个:

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(); 
        } 
}
于 2010-11-15T02:07:35.397 回答