Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

How to create transparent components

For most components and containers, setting the opaque property to false will prevent painting the background (and effectively make them transparent). Use setOpaque() method to change the opaque property of most components.

Some containers (JDesktopPane for example) override getOpaque() method and always return true. If you find a container that still paints the background after setting opaque to false, look at the source of that class1), and see if getOpaque is overridden. To the best of my knowledge, there is absolutely no reason to hard-code the opaque property, so override the method again and return true if you want it transparent - and add the component to the list below.

To get complete transparency on some components and containers, you will have to remove borders. Setting the border to null usually does the trick.

Here is a list of workarounds and fixes for some components that are harder to make transparent:

1) complete Swing source is included in the J2SDK source package

Comments? Corrections? Contact us or Login to edit pages directly (registration is free and takes less than displaying a JLabel)
  howto/transparency.txt · Last modified: 2005/02/14 11:39 by (gojko)
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources

Sedo - Buy and Sell Domain Names and Websites project info: Statistics for project etracker� web controlling instead of log file analysis