layout - TilePane with automatically stretching tiles in JavaFX -


is there way in javafx take best both tilepane or flowpane and gridpane?
here's i'd achieve:

first, idea of gridpane can set m×n grid automatically resizes within parent container divide space equally m columns , n rows. can put child elements fill each cell completely, , stretch along grid. cool.
there's 1 drawback: need explicitly specify should each control go, setting row & column number.

then, there layout containers such flowpane or tilepane automatically reflow child elements when parent container changes size. when add child element, automatically attached @ end of list, , list of elements automatically wraps after reaching edge of container when there's few space fit element in there.
here's drawback well: child elements can have rigid, pre-defined sizes. won't stretch parent element.

and here's need:
need best both of these containers, is, want m n grid (let's 4×4) each cell parentwidth/m parentheight/n , stretches along window, 4×4 cells, sizes (along sizes of contents) stretches accordingly. don't want tell container explicitly in row & column put every new child add there. instead, want add , let container figure out first empty cell put in, filling cells left right, top bottom if there's no empty cell left in current row.

is there magical setup of these predefined containers' attributes allow me achieve this? or need write such container myself?

exactly purpose describing, created buttongridpane . it's first draft, , there still room improvement, maybe can give basic idea.

public class buttongrid extends pane {      private static final double default_ratio = 0.618033987;      private int                 columncount;     private double              ratio;      public buttongrid(int columncount) {         this(columncount, default_ratio);     }      public buttongrid(int columncount, double heighttowidthratio) {         getstyleclass().add("button-grid");         this.columncount = columncount;         ratio = heighttowidthratio;     }      public void setcolumncount(int columncount) {         this.columncount = columncount;     }      public void setheighttowidthratio(double ratio) {         this.ratio = ratio;     }      @override     public orientation getcontentbias() {         return orientation.horizontal;     }      @override     protected void layoutchildren() {         double left = getinsets().getleft();         double top = getinsets().gettop();          double tilewidth = calculatetilewidth(getwidth());         double tileheight = calculatetileheight(getwidth());          observablelist<node> children = getchildren();         double currentx = left;         double currenty = top;         (int idx = 0; idx < children.size(); idx++) {             if (idx > 0 && idx % columncount == 0) {                 currentx = left;                 currenty = currenty + tileheight;             }             children.get(idx).resize(tilewidth, tileheight);             children.get(idx).relocate(currentx, currenty);             currentx = currentx + tilewidth;         }     }      @override     protected double computeprefwidth(double height) {         double w = 0;         (int idx = 0; idx < columncount; idx++) {             node node = getchildren().get(idx);             w += node.prefwidth(-1);         }         return getinsets().getleft() + w + getinsets().getright();     }      @override     protected double computeprefheight(double width) {         double h = calculatetileheight(width) * getrowcount();         return getinsets().gettop() + h + getinsets().getbottom();     }      private double calculatetileheight(double width) {         return calculatetilewidth(width) * ratio;     }      private double calculatetilewidth(double width) {         return (-getinsets().getleft() + width - getinsets().getright()) / columncount;     }      private int getrowcount() {         return getchildren().size() / columncount;     } } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -