Embed HWND (Window Handle) in a JPanel
Asked Answered
C

1

4

I am trying to embed a HWND (Window Handle) in a JPanel.

Actually, I can embed my HWND into a JFrame, but the embedded window alway stay on top of the other component and I can't move it. If a try to remove all the child component of my JFrame, the HWND stay there. The HWND seems to be paint on top of the JFrame and not as one of is child.

To embed the HWND into the JPanel I use User32 through jna:

User32.SetParent(iage.getRenderHwnd(), (int) getGUIHwnd(j));

And I use this to get the HWND of my JFrame:

j.getPeer() != null ? ((WComponentPeer) j.getPeer()).getHWnd(): 0;

Is there a way to embed a HWND into a JPanel or to add it into an other component so I can position it like I wan in my UI?

Thanks

Coumas answered 26/1, 2011 at 20:31 Comment(0)
M
7

JPanels are lightweighted components (they have no real native peer). i.e. they use already the handle of the (J)Frame. Look at java.awt.Canvas.

Mockery answered 27/1, 2011 at 1:9 Comment(2)
Thank you very much, I can link my HWND on the canvas and add it to a JPanel thereafter.Coumas
You welcome! Keep in mind: there could be a lot of unexpected effects mixing heavy-weighed components in light-weighted containers (i.e. Canvas in JPanel), Java did some improvements on the said matter but, still be careful. I have not being using heavy-weighted stuff for like 9 years, though.Mockery

© 2022 - 2024 — McMap. All rights reserved.