当javaFX的控制器不足以显示内容时,它将显示“...”。在末尾? [英] When a javaFX's controller is not enough to display content, it will display "..." at the end?

查看:160
本文介绍了当javaFX的控制器不足以显示内容时,它将显示“...”。在末尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我可以抓住显示事件......吗?

My question is that can I catch the event of display "..." ?

※我的意思是javaFX有一个API判断是否结束了内容被替换为...?

※ I mean does javaFX have a API to judge if the end of the content is replaced with "..."?

事实上,我的问题是,现在我们的测试人员希望我们在一个控制器上设置TIP(如Label) )如果仅仅显示不够。如果内容足以在控制器中显示,那么我们就不需要添加提示了。

In fact, the reason for my question is that now our testers want us to set a TIP on one controller(like Label) if it is only not enough to display. If the content is enough to display in the controller, we don't need to add a TIP then.

推荐答案

这并不容易判断文本是否被剪切的方法。

There's no easy way of telling if a text has been clipped.

这个剪辑是在Labeled对象上完成的,在LabeledSkinBase的实现中,我们可以看到剪切的所有逻辑都是委托给computeClippedText(),它返回一个(剪切或不剪切)字符串:

This clipping is done on Labeled objects, and in the implementation of LabeledSkinBase, we can see that all the logic for clipping is delegated to computeClippedText(), which returns a (clipped or not) String:

result = Utils.computeClippedText(font, s, w, truncationStyle, ellipsisString);
[...]
text.setText(result);

此方法不会获取对Labeled对象的引用,也不会触发任何事件,因此只有我们对computeClippedText()决定剪辑是否有机会查看实际的Text节点( text ),其中包含显示的实际文本。由于Labeled不公开此节点,我们不得不求助于查找:

This method does not get a reference to the Labeled object and does not fire any events, so the only chance we have of whether computeClippedText() decided to clip is to have a look at the actual Text node (text), which contains the actual text being shown. Since Labeled doesn't expose this node, we have to resort to doing a lookup:

String originalString = myLabeled.getText();
Text textNode = (Text) myLabeled.lookup(".text"); // "text" is the style class of Text
String actualString = textNode.getText();

contentHasBeenClipped = originalString.notEquals(actualString);

我们有它!

这篇关于当javaFX的控制器不足以显示内容时,它将显示“...”。在末尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆