我正在尝试向我的 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)
已被忽略。
有什么办法可以克服这个问题吗?
最佳答案
在我的代码中,我在设置宽度之前设置了wrapText(boolean)
。看来JavaFX 不太喜欢这个。我将其更改为如下所示:
TooltipBuilder.create().prefWidth(300).wrapText(true).<other properties>.build();
这给了我一个成功的包装!
关于java - 工具提示不换行/忽略最大宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17801421/