How to make javafx.scene.Scene resize while maintaining an aspect ratio? -


i'm writing application javafx 2.2.7-b01.

here example of code have. how can allow application window resized maintain aspect ratio configured with? in other words, if user resizes window, window width should stay double window height.

  ...   public void showscene(stage stage, string fxmlpath) {     try {       fxmlloader loader = new fxmlloader();       loader.setbuilderfactory(new javafxbuilderfactory());       loader.setlocation(fxmlpath);       parent page;       try (inputstream in = main.class.getresourceasstream(fxmlpath)) {         page = (parent) loader.load(in);       }       scene scene = new scene(page, 400, 200);       stage.setscene(scene);       stage.sizetoscene();       stage.show();     } catch (exception ex) {       ...     }   }   ... 

it seems javafx allows user specify width , height of scene in constructor not allow programmatic access update width or height. there no setwidth or setheight methods. know can add property listeners read only width/height of scene while being resized, haven't been able figure out how change scene dimensions dynamically can force aspect ratio maintained.

i imagine possible if subclass scene object (if have will) there other simple way this?

> how make javafx.scene.scene resize while maintaining aspect ratio?

by manipulating stage size instead of scene:

@override public void start(stage primarystage) {     button btn = new button();     btn.settext("play resizing window");     vbox root = new vbox();     root.getchildren().add(btn);     root.setstyle("-fx-background-color: gray");      scene scene = new scene(root);     primarystage.setscene(scene);     primarystage.minwidthproperty().bind(scene.heightproperty().multiply(2));     primarystage.minheightproperty().bind(scene.widthproperty().divide(2));     primarystage.show(); } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -