How to make JFrame transparent?

后端 未结 2 1993
失恋的感觉
失恋的感觉 2021-01-04 20:36

How to make JFrame transparent? I want to make my JFrame transparent. User should see the background when my JFrame is on top of it.

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 21:23

    I found another solution.

    Set the background color of your frame to

    // Set the frame background color to a transparent color
    yourFrameHere.setBackground(new Color(0, 0, 0, 0));
    

    And remember to set the opacity off of the contentpane (your JPanel or other component)

    // turn off opacity of the content pane
    yourContentPaneHere.setOpaque(false);
    

提交回复
热议问题