Using alpha transparency and Swing

Just an FYI I noticed while using JMEDesktop here at work…



I had some Swing widgets (JTextPane in a JScrollPane and a JTextField) that I wanted to show up as semi transparent over my jME window.  It was easy enough to do so by setting their Background to an awt Color with an alpha < 1…  It looked great at first, but every time a repaint occurred (such as when text was appended to the JTextPane) the widgets became more and more opaque.  It turned out that when Swing was painting over the existing image, the alpha was adding up to 1.  There may be a quick way to get around that, but a quick and dirty method (and the one I used) is to subclass the component and change the paint method like so:


        messagePane = new JTextPane() {
            private static final long serialVersionUID = 1L;
            public void paint(Graphics g) {
                g.clearRect(0,0,getWidth(), getHeight());
                super.paint(g);
            }           
        };



If there is a better method, let me know.

better would be fixing the l&f :stuck_out_tongue:



When one uses a different l&f (e.g. oyoaha) it seems to be fine.

heh, if only…