【问题标题】:Tooltip does not wrap/ignores max width工具提示不换行/忽略最大宽度
【发布时间】:2016-03-10 21:25:39
【问题描述】:

我正在尝试向我的ToggleButton 添加一个工具提示,以向用户解释如果他们按下它会发生什么。问题是,我的解释太长了,工具提示用“...”(省略号字符串,是吗?)无论如何,当我通过TooltipBuilder 设置最大/首选项宽度时,就像在这个例子中一样:

this.watched = new ToggleButton("Watched?");
Tooltip tooltip = TooltipBuilder.create().wrapText(true).text(
                "Rather than specifying individual images, you can make this source \'watched\',which means that every" + 
                " time this gallery is viewed, all the images in this directory will be listed.").build();
tooltip.prefWidth(50);
watched.setTooltip(tooltip);

我得到这个结果:

我通过maxWidth(double)maxWidthProperty().set(double)prefWidth(double)prefWidthProperty().set(double) 设置宽度的尝试已被忽略。

有什么办法可以克服吗?

【问题讨论】:

    标签: java width tooltip javafx word-wrap


    【解决方案1】:

    在我的代码中,我在设置宽度之前设置了wrapText(boolean)。 JavaFX 似乎不太喜欢这个。我将其更改为如下所示:

    TooltipBuilder.create().prefWidth(300).wrapText(true).<other properties>.build();
    

    这给了我一个成功的包装!

    【讨论】:

    • 请注意,TooltipBuilder 在 Java v8 更新 101 中已被弃用(但它仍然有效)。
    【解决方案2】:

    在 javaFx 2.2 中使用这个:

    Tooltip toolTip = TooltipBuilder.create().text(string).prefWidth(500).wrapText(true).build();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-24
      • 2016-10-11
      • 1970-01-01
      • 2023-04-02
      • 2022-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多