【问题标题】:JavaFx: text-overflow:ellipsis analogueJavaFx:文本溢出:省略号模拟
【发布时间】:2015-08-21 21:57:56
【问题描述】:

我有一个选项卡窗格,我希望所有选项卡标题具有相同的宽度。所以我做了:

.tab-header-area .tab{
    -fx-min-width:200;
    -fx-pref-width:200;
    -fx-max-width:200;
}

问题是,如果文本比它所拥有的空间长,那么标签就会与关闭按钮混淆。我怎样才能让.tab > .tab-container > .tab-label剪切文本并在末尾添加“...”?

【问题讨论】:

    标签: java javafx


    【解决方案1】:

    代码选项

    TabPane pane = new TabPane();
    pane.setTabMinWidth(200);
    pane.setTabMaxWidth(200);
    

    CSS 选项

    .tab-pane{
        -fx-tab-min-width:200;
        -fx-tab-max-width:200;
    }
    

    旧解决方案:

    你必须为.tab > .tab-container > .tab-label设置-fx-max-width,有2个选项:

    1) 设置标签而不是标签的默认大小(使用x 按钮,选定的标签会稍微大一点 在里面):

    .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) 使用您的 css 和一些较小的标签值(这样所有标签 将始终为 200 像素):

    .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;
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-22
    • 1970-01-01
    • 2013-04-01
    • 2017-01-21
    • 2019-04-29
    • 2019-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多