How contents are made translucent in a JPanel?

后端 未结 2 580
醉梦人生
醉梦人生 2020-12-12 03:17

I am confused regarding the display of components in a JPanel.

Suppose if I create a custom JPanel with translucency of 0.8f as follows :-

JPanel pan         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 03:43

    Generally, you want to override paintComponent() not paint(). This is likely the cause of your transparency issues. Second, you probably want to change the layout. By default panels use FlowLayout. You likely want to use BorderLayout or GridBagLayout or a mix of the two.

提交回复
热议问题