I want the tabs in my tabpane to fit the complete size of the tabpane which they are in. So basically there shall be no header area visible, everything should be covered by
I'm not sure if this is do-able in CSS, and there might be a simpler way in Java to do this, but I wrote a class that extends TabPane in order to stretch the tabs to fill all the space.
public class StretchedTabPane extends TabPane {
public StretchedTabPane() {
super();
setUpChangeListeners();
}
public StretchedTabPane(Tab... tabs) {
super(tabs);
setUpChangeListeners();
}
private void setUpChangeListeners() {
widthProperty().addListener(new ChangeListener() {
@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() {
@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() {
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 will automatically adjust the width of each tab when the height, width or number of tabs changes.