Hey guys

I'm using JLayeredPane because i want three distinct layers in my program. terrain, buildings and then characters.

I thought that JLayeredPane was easily the best choice for this context. The problem is, I have only seen people *adding* components to their layers. I need to do my own painting, but I don't know how to specify which layer i want to paint to.

Something I just thought of now was perhaps getting the graphics context for a specific frame and painting to that? How would i do that?

Recommended Answers

All 3 Replies

so i should use multiple glass panes and then paint the various layers to a specific glasspane?

Small error in your thinking: you don't paint a layer - you just paint the things in the JLayeredPane and the "layers" determine which things get painted on top of which.
So, you can simply add three things (eg JLabels) to the JLayeredPane, setting their depths appropriately, then override the paint(...) method for each of the three things you added. You will probably also want to take a quick look at how transparency works in Swing (Google) if you want lower things to show thru the gaps in higher things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.