aspose file tools*
The moose likes JavaFX and the fly likes redraw canvas when scene is resized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "redraw canvas when scene is resized" Watch "redraw canvas when scene is resized" New topic
Author

redraw canvas when scene is resized

Carl Bernardi
Greenhorn

Joined: Jan 15, 2013
Posts: 23
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.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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!


luck, db
There are no new questions, but there may be new answers.
Carl Bernardi
Greenhorn

Joined: Jan 15, 2013
Posts: 23
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
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Oh. I see you have a newer version of FX than I have.

Time to update.
Carl Bernardi
Greenhorn

Joined: Jan 15, 2013
Posts: 23
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.
Carl Bernardi
Greenhorn

Joined: Jan 15, 2013
Posts: 23
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.


Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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.
Carl Bernardi
Greenhorn

Joined: Jan 15, 2013
Posts: 23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: redraw canvas when scene is resized
 
Similar Threads
making resizable components?
tell me this!!
how to move a string
Problem in drawing block using java3d
Flickering of Canvas