Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

redraw canvas when scene is resized

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He baked a muffin that stole my car! And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic