Skip to main content

Adding AWT or SWING component on top of canvas 3D.

2 replies [Last post]
ulib
Offline
Joined: 2009-07-28

Hi everybody,

for the application I am developing at the Moment, I would need to show some Information in 2D at several times. I would like to show this information on a standard JPanel thats partly overlapping my Canvas3D. Is this feasible somehow? I know there would also be the option to just open a second window - but I would really prefer doing it inside the frame that is already opened!

Thanks & Regards,

Uli

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lamer77
Offline
Joined: 2006-12-22
chrismcband
Offline
Joined: 2006-07-10

As far as I know you can not display a swing component on top of a Canvas3D unless it is in another window as you pointed out. It's due to the heavyweight component problem, swing components only render when they have to, whereas Canvas3D which is heavyweight, renders more frequently and takes priority over the screen, the result is that you don't see the swing component at all, only the canvas.
You could probably try this with a JDialog which is undecorated and in the position you want. AWT components should work (they are heavyweight too), though I've always used Swing and can't help you with that.

If you don't require interaction with the 2D info you need to display, you could implement an overlay. You can do this by creating the swing component you want to display and drawing the component onto a BufferedImage. You might have to explicitly size the component and manually position the subcomponents to get the component to draw on the image. Once you have the image you can draw it where you like on the screen by overriding the postRender() method of Canvas3D. Have a look for 2D overlays for examples how to do this.
Working with image overlays gives you a bit of flexibility, you can display the image semi-transparent and apply image effects, but getting it all to work in the first place is a bit of a hassle.