java - javafx custom layout pane: label always returns -1 for its preferred width and height -
i try implement custom layout pane in javafx position nodes in circle around center. problem nodes return -1.0 preferredwidth , minwidth , height properties. here class:
public class circlepane extends region { @override protected void layoutchildren() { double middlex = getwidth() / 2; double middley = getheight() / 2; double factor = math.min(getwidth(), getheight()) * 0.45;// how far middle nodes arranged double degreesperchild = 2 * math.pi / getchildren().size(); (int = 0; < getchildren().size(); i++) { if(getchildren().get(i) instanceof region){ region r = (region) getchildren().get(i); // believe need region sizes? double prefw = math.max(r.getminwidth(), r.getprefwidth()); //my attempt reliable preferredwidth , height double prefh = math.max(r.getminheight(), r.getprefheight()); double degrees = * degreesperchild; double xpos = math.sin(degrees) * factor + middlex - prefw / 2; double ypos = math.cos(degrees) * factor + middley - prefh / 2; layoutinarea(r, xpos , ypos, prefw, prefh, 0.0d, hpos.left, vpos.center); } } } @override public observablelist<node> getchildren() { return super.getchildren(); }
it works, nodes moved right (a few pixels, approximately width / 2). also, want make sure other components fit correctly.
i found solution myself. right width , height, have call region.prefwidth(-1)
, region.prefheight(-1)
respectively.
the purpose of these 2 functions be:
called during layout determine preferred width/height node.
Comments
Post a Comment