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

bestsss
  • 11,796
  • 3
  • 53
  • 63
Etienne
  • 1,024
  • 25
  • 33

1 Answers1

6

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.

bestsss
  • 11,796
  • 3
  • 53
  • 63
  • Thank you very much, I can link my HWND on the canvas and add it to a JPanel thereafter. – Etienne Jan 27 '11 at 14:17
  • 1
    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. – bestsss Jan 27 '11 at 14:22