• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redraw canvas when scene is resized

 
Carl Bernardi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Carl Bernardi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh. I see you have a newer version of FX than I have.

Time to update.
 
Carl Bernardi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic