Javafx : test with a layout manager? -


i'm learning javafx , made few try vbox layout manager. code seems ok wanna check if understood how works.

here code :

public class testshape2 extends application {    public static void main(string[] args) {       launch(args);   }    @override   public void start(stage primarystage) throws exception {       group root = new group();       label toplabel = new label("top...");       label toplabel2 = new label("top 2...");       rectangle rect = new rectangle();        rect.setfill(color.aqua);       label bottomlabel = new label("bottom...");        vbox vbox = new vbox();       rect.widthproperty().bind(vbox.widthproperty());       rect.heightproperty().bind(vbox.heightproperty());        vbox.getchildren().addall(toplabel, toplabel2, rect, bottomlabel);       /*        * code 1        */       root.getchildren().add(vbox);       scene scene = new scene(root, 300, 300, color.blanchedalmond);        /*        * code 2        */       // scene scene = new scene (vbox, 300, 300, color.blanchedalmond);        primarystage.setscene(scene);       primarystage.show();    }  } 

in "code 1" : width , height of vbox of elements contained in root ass root group parent of vbox ? , so, vbox don't fill whole space ? in "code 2" : don't use root group, vbox dimensions ones of scene scene parent of vbox ? understanding correct ?

if that's correct, question : code have "top label", "bottom label" , rectangle fill free space ? in code 2, never see bottom label" seems rectangle height height of scene so, suppose bottom label out of scene. how solve ?

thank in understanding javafx

this

rect.heightproperty().bind(vbox.heightproperty()); 

is thing should not do. resizes rectangle according size of parent. there height of parent depends on size of children. circular dependency leads vbox's behavior no longer being defined...

in "code 1" : width , height of vbox of elements contained in root ass root group parent of vbox ?

the size of group's children prefered size. combined issue described above layout not fill whole width/height available.

in "code 2" : don't use root group, vbox dimensions ones of scene scene parent of vbox ?

mostly correct except imprecise formulation: scene not parent of node. vbox root of scene , scene contains vbox.

in code 2, never see bottom label" seems rectangle height height of scene so, suppose bottom label out of scene.

that correct.

rectangle not resizable doesn't work vbox parent achieve desired behavior. can use ´region´ instead however, resizable. filling can done using region's background , stroke replaced border, if needed.

setting vgrow priority.always tells vbox resize region instead of other children , setting fillwidth true tells vbox change children's size it's own width:

@override public void start(stage primarystage) throws exception {     label toplabel = new label("top...");     label toplabel2 = new label("top 2...");      region rect = new region();     rect.setbackground(new background(new backgroundfill(color.aqua, cornerradii.empty, insets.empty)));      label bottomlabel = new label("bottom...");      vbox vbox = new vbox();     vbox.setfillwidth(true);      vbox.setvgrow(rect, priority.always);      vbox.getchildren().addall(toplabel, toplabel2, rect, bottomlabel);      scene scene = new scene (vbox, 300, 300, color.blanchedalmond);     primarystage.setscene(scene);     primarystage.show(); } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -