Bevin
Bevin

Reputation: 972

Z-order on Java Swing components

I've been looking all over for some mention of this, but I cannot find any substantial information on it. Is there a way to change the z-order of Swing components, or at least change the draw order so that they appear to be above others?

Upvotes: 17

Views: 35444

Answers (3)

Amir Afghani
Amir Afghani

Reputation: 38531

You are looking for setComponentZOrder

Here's an example.

Upvotes: 20

camickr
camickr

Reputation: 324108

Look at the setComponentZOrder(...) method of the Container class.

You can also check out the Overlap Layout which has a brief description on how ZOrder works.

Upvotes: 2

Reverend Gonzo
Reverend Gonzo

Reputation: 40811

If you want to overlay components over other components, you should use JLayeredPane, which will let you add components to specific layers. This is precisely what's used for things like tooltips and drag-and-drop operations.

Here's a tutorial for it as well.

Upvotes: 4

Related Questions