Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with transparent panel

Status
Not open for further replies.

mindfac

Programmer
May 15, 2002
1
DE
good morning!

there is a problem i´ve got...
i´m writing on an application, that uses an jpg image as a background picture (attached to the frame). on top of that background there are other panels, that include some buttons and labels.
does anybody know how i can make the panel´s background transparent? i have to use panels in order to keep a formation of the buttons and labels.
(btw i´m not used to Java3D classes).

i would appreciate it, if anybody could help me out...

mindfac
 
I found this reference on the Sun tutorial site:

"By default, panels are opaque. This makes them work well as content panes, and can help painting efficiency, as described in Painting. You can make a panel transparent by invoking setOpaque(false). A transparent panel draws no background, so that any components underneath show through. "

The full tutorial page is here:
I've never done it, so I'm interested to learn if it works. "When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle
 
The problem with panels is that when U set panel opacity to false, U don't set contained panels opacity. So I made a recursive static method that I stored into a Toolkit class that does it. Here it is for U guys :
Code:
public static void setPanelOpacity(JPanel aPanel, boolean aOpaque) {
	aPanel.setOpaque(aOpaque);
	Component[] listComp = aPanel.getComponents();
	for (int i = 0; i< listComp.length; i++) {
		if (listComp[i] instanceof JPanel) {
			setPanelOpacity((JPanel)listComp[i], aOpaque);
		} else if (listComp[i] instanceof JComponent) {
			((JComponent)listComp[i]).setOpaque(aOpaque);
		}
	}
}

Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top