css - JavaFX Tab fit full size of header -
i want tabs in tabpane fit complete size of tabpane in. there shall no header area visible, should covered tabs.
i have 2 problems here:
- how can make tabs dynamically fit width of tabpane?
- how can fit them correct height, , remove little spaces between tabs? suppose done via css, don't quite know how.
greets
i'm not sure if do-able in css, , there might simpler way in java this, wrote class extends tabpane in order stretch tabs fill space.
public class stretchedtabpane extends tabpane { public stretchedtabpane() { super(); setupchangelisteners(); } public stretchedtabpane(tab... tabs) { super(tabs); setupchangelisteners(); } private void setupchangelisteners() { widthproperty().addlistener(new changelistener<number>() { @override public void changed(observablevalue<? extends number> value, number oldwidth, number newwidth) { side side = getside(); int numtabs = gettabs().size(); if ((side == side.bottom || side == side.top) && numtabs != 0) { settabminwidth(newwidth.intvalue() / numtabs - (20)); settabmaxwidth(newwidth.intvalue() / numtabs - (20)); } } }); heightproperty().addlistener(new changelistener<number>() { @override public void changed(observablevalue<? extends number> value, number oldheight, number newheight) { side side = getside(); int numtabs = gettabs().size(); if ((side == side.left || side == side.right) && numtabs != 0) { settabminwidth(newheight.intvalue() / numtabs - (20)); settabmaxwidth(newheight.intvalue() / numtabs - (20)); } } }); gettabs().addlistener(new listchangelistener<tab>() { public void onchanged(listchangelistener.change<? extends tab> change){ side side = getside(); int numtabs = gettabs().size(); if (numtabs != 0) { if (side == side.left|| side == side.right) { settabminwidth(heightproperty().intvalue() / numtabs - (20)); settabmaxwidth(heightproperty().intvalue() / numtabs - (20)); } if (side == side.bottom || side == side.top) { settabminwidth(widthproperty().intvalue() / numtabs - (20)); settabmaxwidth(widthproperty().intvalue() / numtabs - (20)); } } } }); } }
this automatically adjust width of each tab when height, width or number of tabs changes.
Comments
Post a Comment