Transparent JFrame background

后端 未结 5 884
温柔的废话
温柔的废话 2021-02-15 16:31

Is it possible to make a JFrame that has a transparent background and draw an image on it, so only the image will be visible with no border or background?

相关标签:
5条回答
  • 2021-02-15 16:54

    See Translucent and Shaped Swing Windows by Kirill Grouchnikov.

    0 讨论(0)
  • 2021-02-15 16:57

    It is possible.

    If your JFrame is a local variable or field:

    myJFrame.setUndecorated(true);
    

    If your class extends JFrame:

    setUndecorated(true);
    
    0 讨论(0)
  • 2021-02-15 16:58

    Yes, it's possible in many ways. This is one of them:

    setUndecorated(true);
    setBackground(new Color(1.0f,1.0f,1.0f,0.5f));
    

    4th float (which I set to 0.5f) in Color's constructor is alpha channel. It can be 0.0f - 1.0f depend on transparency you want.

    0 讨论(0)
  • 2021-02-15 17:03

    For a Mac OS X example, see Re-paint problem on translucent frame/panel/component.

    0 讨论(0)
  • 2021-02-15 17:09

    You should make content pane transparent too.

    frame.setUndecorated(true);
    frame.getContentPane().setBackground(new Color(1.0f,1.0f,1.0f,0.0f));
    frame.setBackground(new Color(1.0f,1.0f,1.0f,0.0f));
    
    0 讨论(0)
提交回复
热议问题