javafx - Autosize to parent -


i have simple example. want autosize chart fill parent.

@override     public void start(stage primarystage)     {          flowpane flowpane = new flowpane(orientation.horizontal);          flowpane.getchildren().addall(test());         flowpane.setpadding(new insets(5, 5, 5, 5));         flowpane.setstyle("-fx-background-color: green;");         //flowpane.setprefwidth(1200);         flowpane.setvgap(4);         flowpane.sethgap(4);         flowpane.setalignment(pos.top_left);          scrollpane scroll = new scrollpane();         scroll.setstyle("-fx-background-color: transparent;");         scroll.sethbarpolicy(scrollpane.scrollbarpolicy.as_needed);    // horizontal scroll bar         scroll.setvbarpolicy(scrollpane.scrollbarpolicy.as_needed);    // vertical scroll bar         scroll.setfittoheight(true);         scroll.setfittowidth(true);         scroll.setcontent(flowpane);          scene scene = new scene(scroll, 1500, 250);          primarystage.settitle("hello world!");         primarystage.setscene(scene);         primarystage.show();     }      public static void main(string[] args)     {         launch(args);     }      private areachart<string, number> test()     {         categoryaxis xaxis = new categoryaxis();          numberaxis yaxis = new numberaxis();          final areachart<string, number> sc = new areachart<>(xaxis, yaxis);         sc.setanimated(false);  // turn off chart animation during first appearance          sc.setcreatesymbols(false);          sc.setprefsize(1200, 210);          return sc;     } 

how can auto size chart fill parent size? there simple solution without binding?

can propose solution?

so, since want fill whole parent 1 graph anyway, don't think there's reason use flowpanefor that. better use stackpane instead

public void start(stage primarystage) {      stackpane stackpane = new stackpane();     areachart<string, number> chart = test();     stackpane.setalignment(chart, pos.center);     stackpane.getchildren().add(chart);     stackpane.setstyle("-fx-background-color: green");  //  flowpane flowpane = new flowpane(orientation.horizontal); // //  flowpane.getchildren().addall(test()); //  flowpane.setpadding(new insets(5, 5, 5, 5)); //  flowpane.setstyle("-fx-background-color: green;"); //  //flowpane.setprefwidth(1200); //  flowpane.setvgap(4); //  flowpane.sethgap(4); //  flowpane.setalignment(pos.top_left);      scrollpane scroll = new scrollpane();     scroll.setstyle("-fx-background-color: transparent;");     scroll.sethbarpolicy(scrollpane.scrollbarpolicy.as_needed);    // horizontal scroll bar     scroll.setvbarpolicy(scrollpane.scrollbarpolicy.as_needed);    // vertical scroll bar     scroll.setfittoheight(true);     scroll.setfittowidth(true); //  scroll.setcontent(flowpane);     scroll.setcontent(stackpane);      scene scene = new scene(scroll, 1500, 250);      primarystage.settitle("hello world!");     primarystage.setscene(scene);     primarystage.show(); } 

however if want use flowpane, use binding. in case it's easy. it's simple 2 lines of code

    chart.prefwidthproperty().bind(flowpane.widthproperty().subtract(10)); //substract 10 because of 5px insets on each side     chart.prefheightproperty().bind(flowpane.heightproperty().subtract(10)); //same here 

here preferred width , height of chart equal width , height of flowpane minus 10 (because of insets)


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -