Forums Register Login

redraw canvas when scene is resized

+Pie Number of slices to send: Send
Trying to figure out how to redraw all methods that I use to draw in GraphicsContext from Canvas when it's parent Scene is resize.
+Pie Number of slices to send: Send
I don't see either a GraphicsContext or a Canvas in the Java FX API. Is your question maybe about Swing or AWT?

Oh, and welcome to the Ranch!
+Pie Number of slices to send: Send
Hi Darryl,

Thanks for the welcome. Canvas is under:
java.lang.Object
javafx.scene.Node
javafx.scene.canvas.Canvas

You can get the GraphicsContext by calling canvas.getGraphicsContext2D();

And GraphicsContext is found under:
java.lang.Object
javafx.scene.canvas.GraphicsContext

GraphicsContext used much like Grapihcs2D in AWT.

Thanks,

Carl
+Pie Number of slices to send: Send
Oh. I see you have a newer version of FX than I have.

Time to update.
+Pie Number of slices to send: Send
I have been trying to bind the widthProperty and the heightProperty from Scene and Canvas to call a redraw method that has all my GraphicsContext methods inside.
+Pie Number of slices to send: Send
I tried calling the parent class which is group. It compiles but I get this runtime error:



This is the code that I used. I tried to get the scene which is what the group class is added too. Wasn't able to get it.


+Pie Number of slices to send: Send
OK I've updated NetBeans and JavaFX and I now have those classes. I'm not sure what redrawing is needed on resizing, unless of course your custom painting is in some way determined by the current size. Can you post a small compilable program -- a SSCCE <- link that demonstrates the problem?

I have been trying to bind the widthProperty and the heightProperty from Scene and Canvas to call a redraw method that has all my GraphicsContext methods inside.


You may need to wrap that in a Platform#invokeLater to allow all core FX code to complete first.
+Pie Number of slices to send: Send
I figured out why I was getting a null error. First I was using the wrong method to get Scene and secondly I was calling the method before my chart was add to the scene. So this how I over came it.



I would like to use a bind method as the changelistener seams to be a little clunky.
The knights of nee want a shrubbery. And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 10652 times.
Similar Threads
making resizable components?
how to move a string
Problem in drawing block using java3d
tell me this!!
Flickering of Canvas
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:15:29.