No luck with setClipRect on canvas

Hi there,



I’m using a JME swing canvas, bordered by a heap of swing components.



I’m trying to make a JPanel ‘pop-out’ from the left side of the screen overlayed over my JME canvas, but this is obviously easier said than done. Obviously swing components are lightweight and cannot be drawn over the top of the JME canvas, so I was hoping to set a clip rectangle where the ‘pop-out’ will go as to allow the swing component to be drawn.



Unfortunately, whatever I try, setClipRect is having no effect. My canvas is being drawn no differently.



I am creating my canvas as such:

[java]

mySimpleGame.createCanvas();

JmeCanvasContext ctx = (JmeCanvasContext) sr.getContext();

ctx.setSystemListener(mySimpleGame);

myJFrame.add(ctx.getCanvas());

[/java]



And clipping as such (in mySimpleGame):

[java]

this.getRenderer().setClipRect(10, 10, 200, 200);

[/java]



Where x, y, width and height are arbitrary values for now.



Any thoughts? Even if I get the clipping to work - will I be able to draw a swing component in that space?

Well first of all you need to decide, do you need jme in a swing window or a swing window in jme?

Both is possible, the first is with a performance penalty (copy the framebuffer of jme into a bufferdimage, then it is also lightweight), while the second is with high complexity.

hmmm - so the setClipRect approach won’t work?

I doubt it is something that anyone has tried to do tbh.



Why do you want to show a panel over the canvas? Could you achieve the same using nifty (for example) for in-canvas UI and swing for out-canvas ui.



One alternative may be to use a JDesktopPane. You can set the background of the JDesktopPane to be the jme canvas and then in theory popup windows etc can go over it. I think you are still going to struggle though as swing has very slow redraws so only redraws when needed…while JME is redrawing every frame…which would (at least potentially) overwrite any windows/panels/etc on top of the canvas.



You might need to tweak the canvas code some?

You can use an AWT panel instead of canvas, that way the jME3 display is a light-weight component. See the TestAwtPanels example.