Swing component overlay AWT component

Hi all,

I know this has been asked a lot of times and it is a long running pain for developers. But I still need to seek your opinions:

My project needs me to implement JXPanel over AWT component in an AWT Frame.

How can it be done? Are there any Swing hack methods or programs to do this?

I have tried using Java 1.5 Container.setComponentZOrder() with Windows XP to set the Z-order. But it fails to set the z-order. My test code for using Container.setComponentZOrder() is as follows:

Frame headlessFrame = new Frame();

headlessFrame.setLayout(null);

headlessFrame.setUndecorated(true);

headlessFrame.setSize(1000,600);

JLayeredPane swingPane = new JLayeredPane();

swingPane.setSize(800,500);

Button awtButton = new Button("AWT Button");

awtButton.setSize(50,50);

Panel awtPanel = new Panel();

awtPanel.setSize(300,300);

awtPanel.add(awtButton);

JButton swingButton = new JButton("Swing Button");

swingButton.setSize(200,200);

JXPanel swingxPanel = new JXPanel();

swingxPanel.setSize(300,300);

swingxPanel.setAlpha(0.5f);

swingxPanel.add(swingButton);

headlessFrame.add(awtPanel);

headlessFrame.add(swingxPanel);

try{

headlessFrame.setComponentZOrder(awtPanel,1);

headlessFrame.setComponentZOrder(swingxPanel,0);

} catch(Exception e){

e.printStackTrace();

}

headlessFrame.setVisible(true);

Thks for the help. Rgds.

[1509 byte] By [OpGinraia] at [2007-10-3 8:50:41]
# 1
Lesson 1: Never ever mix Swing and AWT!
PhHeina at 2007-7-15 4:00:08 > top of Java-index,Desktop,Core GUI APIs...
# 2

> Lesson 1: Never ever mix Swing and AWT!

Lesson 2: Never ever mix Swing and AWT!

Lesson 3: Never ever mix Swing and AWT!

Lesson 4: Never ever mix Swing and AWT!

Lesson 5: Never ever mix Swing and AWT!

...

(why do people keep wanting to try this?)

KelVarnsona at 2007-7-15 4:00:08 > top of Java-index,Desktop,Core GUI APIs...
# 3
> I know this has been asked a lot of timesAnd the answer won't change just because you ask it one more time.[url http://java.sun.com/products/jfc/tsc/articles/mixing/index.html]Mixing Heavy and Light Components[/url].
camickra at 2007-7-15 4:00:08 > top of Java-index,Desktop,Core GUI APIs...
# 4

i was just wondering if there are any newly developed methods to overcome this problem. for example, java 1.5 has introduced the container method to manage z-order. unfortunately, it does not work well.

it's not me who is requesting to do the impossible of mixing awt with swing. it's just what the project requirement states.

this is just one of those things that projects will always request to do, just like the request for translucent frames.

anyway, thks for the replies.

OpGinraia at 2007-7-15 4:00:08 > top of Java-index,Desktop,Core GUI APIs...
# 5
it's not me who is requesting to do the impossible... it's just what the project requirement statesWe've all been there, it's like being in a Dilbert cartoon. But it doesn't change the fact that the impossible is impossible.
itchyscratchya at 2007-7-15 4:00:08 > top of Java-index,Desktop,Core GUI APIs...