JavaFx:text-overflow:省略号模拟
JavaFx: text-overflow:ellipsis analogue
我有一个选项卡窗格,我希望所有选项卡 headers 具有相同的宽度。所以我做了:
.tab-header-area .tab{
-fx-min-width:200;
-fx-pref-width:200;
-fx-max-width:200;
}
问题是,如果文本比 space 长,标签就会被关闭按钮弄乱。如何让 .tab > .tab-container > .tab-label
剪切文本并在末尾添加“...”?
代码选项:
TabPane pane = new TabPane();
pane.setTabMinWidth(200);
pane.setTabMaxWidth(200);
Css 选项
.tab-pane{
-fx-tab-min-width:200;
-fx-tab-max-width:200;
}
旧解:
You have to set -fx-max-width
for .tab > .tab-container > .tab-label
There are 2 options:
1) Set the default sizes for label and not tab (selected tab will be a little bit larger with x
button
in it):
.tab-pane > .tab-header-area > .headers-region > .tab > .tab-container > .tab-label {
-fx-min-width:200;
-fx-pref-width:200;
-fx-max-width:200;
}
2) Use your css and some smaller value for labels(This way all tabs
will be always 200 px):
.tab-header-area .tab{
-fx-min-width:200;
-fx-pref-width:200;
-fx-max-width:200;
}
.tab-pane > .tab-header-area > .headers-region > .tab > .tab-container > .tab-label {
-fx-min-width:175;
-fx-pref-width:175;
-fx-max-width:175;
}
我有一个选项卡窗格,我希望所有选项卡 headers 具有相同的宽度。所以我做了:
.tab-header-area .tab{
-fx-min-width:200;
-fx-pref-width:200;
-fx-max-width:200;
}
问题是,如果文本比 space 长,标签就会被关闭按钮弄乱。如何让 .tab > .tab-container > .tab-label
剪切文本并在末尾添加“...”?
代码选项:
TabPane pane = new TabPane();
pane.setTabMinWidth(200);
pane.setTabMaxWidth(200);
Css 选项
.tab-pane{
-fx-tab-min-width:200;
-fx-tab-max-width:200;
}
旧解:
You have to set
-fx-max-width
for.tab > .tab-container > .tab-label
There are 2 options:1) Set the default sizes for label and not tab (selected tab will be a little bit larger with
x
button in it):.tab-pane > .tab-header-area > .headers-region > .tab > .tab-container > .tab-label { -fx-min-width:200; -fx-pref-width:200; -fx-max-width:200; }
2) Use your css and some smaller value for labels(This way all tabs will be always 200 px):
.tab-header-area .tab{ -fx-min-width:200; -fx-pref-width:200; -fx-max-width:200; } .tab-pane > .tab-header-area > .headers-region > .tab > .tab-container > .tab-label { -fx-min-width:175; -fx-pref-width:175; -fx-max-width:175; }