工具提示不会包装/忽略最大宽度

时间:2013-07-23 04:19:27

标签: java width tooltip javafx textwrapping

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

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);

我得到了这个结果:

tooltip

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

有没有办法克服这个问题?

2 个答案:

答案 0 :(得分:2)

在我的代码中,我在设置宽度之前设置了wrapText(boolean)。似乎JavaFX不太喜欢这个。我改变它看起来像这样:

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

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

enter image description here

答案 1 :(得分:0)

在javaFx 2.2中使用:

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