1

How to set the opacity of a jPanel in Java NetBeans? As we right click on jPanel and go to properties, there is only one option that is opaque(Related to opacity) which does not set the transparency of panel. How can we set transparency on that particular jPanel?

Tanmay Bairagi
  • 564
  • 5
  • 25
  • You can use this link for better understanding – BurakB Jun 11 '17 at 18:11
  • Swing only supports full transparent or fully opaque based background colors. In order to be able to support this feature, you will need to make the component transparent (`setOpaque(false)`) you will need override the component's `paintComponent` method and fill it with the transparent color – MadProgrammer Jun 11 '17 at 23:20
  • [For example](https://stackoverflow.com/questions/31105099/jpanel-not-keeping-color-alpha-when-changing-background/31105289#31105289), [example](https://stackoverflow.com/questions/32216625/how-to-make-a-translucent-jpanel-within-the-region-jpanel/32217554#32217554) – MadProgrammer Jun 11 '17 at 23:25

1 Answers1

-2

You can use JPanel.setBackground(Color bg); to make the panel transparent or semi transparent

panel.setBackground( new Color(r, g, b, a) );
Saubhagya
  • 155
  • 12
  • No, you can't. Swing doesn't support alpha based background colors and doing so will generate any number of graphical artifacts – MadProgrammer Jun 11 '17 at 23:17