本文介绍了JavaFX Tab适合完整大小的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的标签页中的标签符合他们所在的标签页的完整大小。因此,基本上没有标题区域可见,所有内容都应该被标签覆盖。
我在这里有2个问题:
- 如何使标签动态适应标签页的宽度?
- 如何将它们调整到正确的高度,并删除标签之间的小空格?我想这是通过css,但我不知道如何。
greets
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 == b.BTTOM || side == Side.TOP)&& numTabs!= 0){
setTabMinWidth(newWidth.intValue()/ numTabs - (20));
setTabMaxWidth .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)&& != 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));
}
}
}
});
}
}
这将自动调整每个标签的宽度标签的高度,宽度或数量会发生变化。
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 the tabs.
I have 2 problems here:
- How can I make the tabs dynamically fit the width of the tabpane?
- How can I fit them to the correct height, and remove the little spaces between the tabs? I suppose this is done via css, but I don't quite know how.
greets
解决方案
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<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 will automatically adjust the width of each tab when the height, width or number of tabs changes.
这篇关于JavaFX Tab适合完整大小的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!