1

I work with java and I want to make a translucent window (like a black with 80% alpha). The basis of my code is those in the following post: How to make a transparent JFrame but keep everything else the same?

The problem is that when I run my program, the window is translucent but as you may see on the following picture, the background color (magenta) appears only on the text, not on the white. enter image description here Even worse, when I choose a black with transparency Color(0,0,0,125) as drawing color, nothing appears on the screen.

Here is what I have so far :

public class DssWindow extends JFrame
{
    /**
     * 
     */
    private static final long serialVersionUID = 2455172975892566000L;

    /**
     * 
     */
    public DssWindow()
    {
        super("My frame");

        setUndecorated(true);   
        setBackground(new Color(0,0,0,0));
        setAlwaysOnTop(true);
        JPanel contentPane = new JPanel()
        {
            @Override
            public void paintComponent(Graphics g)
            {
                super.paintComponent(g);
                if(!(g instanceof Graphics2D))
                {
                    return;
                }
                Graphics2D gr = (Graphics2D)g.create();
                gr.setColor(new Color(255,0,255,200));
                gr.fillRect(0, 0, getWidth(), getHeight());
            }
        };
        contentPane.setOpaque(false);
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        contentPane.setPreferredSize(new Dimension(screen.width,screen.height));
        setContentPane(contentPane);
        pack();
    }
}

Do someone knows/has a clue of what is the problem ? I am working on Linux (may this is a part of the answer).

Thank you.

Community
  • 1
  • 1
dooxe
  • 1,481
  • 12
  • 17
  • Possible duplicate of [How to make a transparent JFrame but keep everything else the same?](http://stackoverflow.com/questions/14927980/how-to-make-a-transparent-jframe-but-keep-everything-else-the-same) – ug_ Nov 01 '15 at 10:06
  • That is not a duplicate. I used this post to make my program. It is another problem I have. – dooxe Nov 01 '15 at 11:33

1 Answers1

1

Ok, my problem is stated here: Java Window Translucency on Linux Graphics drivers seems to be the cause of this behaviour.

Community
  • 1
  • 1
dooxe
  • 1,481
  • 12
  • 17