a swing component on top of another

A

alex_us01

hello,

Is it possible to put a swing component on top of another and
make at least the one on the top transparent so that the
contents of both are visible?

My specific problem is that I am using a package (JUNG) that
knows how to draw graphs (vertices and edges, etc.),
but I want to draw rectangles around groups of vertices,
and add text over or under the rectangles (via JLabels).
It is not possible to put these directly in JUNG's GraphDraw
Swing component. Therefore, I am looking for a way to put my
components separately on top of it visually and make them transparent
so that the contents of the underlying GraphDraw component are visible.

thanks,
alex
 
A

alex_us01

I found JLayeredPane. Maybe with JComponent.setOpaque(false) will work
I hoped. But when I tried to use JLayeredPane, nothing in it shows up.

I will post that in another topic with name "JLayeredPane possible in
BorderLayout.CENTER ?"

thanks,
alex
 
R

Roedy Green

Is it possible to put a swing component on top of another and
make at least the one on the top transparent so that the
contents of both are visible?

Transparent does not mean quite the same thing as it does in ordinary
English. Fully transparent means the final colour is made by adding
up the r g b of the layers. Black covers nothing. White obliterates
any detail on other layers. It is counterintuitive, but logical.

For overlapping components see
http://mindprod.com/jgloss/jlayeredpane.html

I have never tried this, but I would think you should get some
transparent effects just by drawing your components with colours with
an alpha channel (the high order byte of a 32-bit colour number) with
something other than 255 (fully opaque). Try setting it at 127 to
start.

The transparency I am familiar with is creating png and screen bit
images where you paint with partly transparent colours. See
http://mindprod.com/applets/masker.html for sample code.
 
T

Tor Iver Wilhelmsen

alex_us01 said:
Is it possible to put a swing component on top of another and
make at least the one on the top transparent so that the
contents of both are visible?

setOpaque(false) is your friend.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top