[External] : Re: Q: Labeled.textTruncated Property (RFE)

Andy Goryachev andy.goryachev at oracle.com
Fri Mar 8 21:40:49 UTC 2024


Daniel:

Thank you, both the PR and the code have been updated.

This change provides an illustration of the problem we have with JavaFX - it is nearly impossible to talk about custom skin development when most of the essential machinery is hidden behind accessors and non-public classes.  In this particular case, TableCellSkin and TreeTableCellSkins use what appears to be a "hack" - Properties.DEFER_TO_PARENT_PREF_WIDTH to irreversibly override the behavior of computePrefWidth() methods.  So anyone who wants to modify these skins, or to change Labeled skin to work nicely inside a tree/table is going to hit a brick wall in the form of com.sun.javafx.scene.control.Properties.

This is a separate issue that was raised many times in this forum.  There is currently no easy solution - making every class public and extendable is out of the question (by design and by general consensus of the maintainers), the next best thing we can do is to identify missing APIs - APIs that **can** be made public to achieve extensibility, in each particular case.  This is too not an easy task, as anyone who reads this forum regularly can see.

Still, our goal is to make JavaFX a viable and powerful platform, and I agree with Marius that we might want to start collecting info on the APIs that either missing or need to be made public (something like https://bugs.openjdk.org/browse/JDK-8300569 ☂ Missing APIs related to rich text control ?)

-andy

From: Daniel Peintner <daniel.peintner at gmail.com>
Date: Friday, March 8, 2024 at 00:30
To: Andy Goryachev <andy.goryachev at oracle.com>
Cc: openjfx-dev at openjdk.org <openjfx-dev at openjdk.org>
Subject: Re: [External] : Re: Q: Labeled.textTruncated Property (RFE)
Andy, Marius, all,

Thank you for your input and your insights.

If I understand correctly we cannot purely do it with public methods for now (at least not for TableCells)

This makes the argument to support https://github.com/openjdk/jfx/pull/1389<https://urldefense.com/v3/__https:/github.com/openjdk/jfx/pull/1389__;!!ACWV5N9M2RV99hQ!Lt6vRjwJFIaC7l3TaV-Dls88HkxaORG8T76UGt3J0pwZqHSeWS2dDHSOYUeY5iJxjo-wQO_8Hq_6J4Ie5HJiJKBLfPfJH8o$> even stronger and maybe should be mentioned in the PR as well.

Thanks,

-- Daniel



On Thu, Mar 7, 2024 at 7:53 PM Andy Goryachev <andy.goryachev at oracle.com<mailto:andy.goryachev at oracle.com>> wrote:
Daniel:

Thank you for providing a sample app!

You are right: turns out Labeled in a TableView (in a TreeTableView as well) lives by different rules (TableCellSkinBase:152, TreeTableCellSkin:126).

The consequence of this is that the new functionality **cannot** be fully implemented with the public APIs alone.

Cheers,
-andy



From: Daniel Peintner <daniel.peintner at gmail.com<mailto:daniel.peintner at gmail.com>>
Date: Thursday, March 7, 2024 at 07:11
To: Andy Goryachev <andy.goryachev at oracle.com<mailto:andy.goryachev at oracle.com>>
Cc: openjfx-dev at openjdk.org<mailto:openjfx-dev at openjdk.org> <openjfx-dev at openjdk.org<mailto:openjfx-dev at openjdk.org>>
Subject: Re: [External] : Re: Q: Labeled.textTruncated Property (RFE)
Andy, all,

Some comments below:

  1.  Even if it is possible to do the same with public means I think it is useful. Anyhow we need to promote the solutions better (e.g., on StackOverflow)
  2.  I tried to achieve what you did in JavaFX core for my use-case, TableView cells.

     *   In my real application I tried and failed since the boolean condition in https://github.com/openjdk/jfx/blob/8a5cb17ed6525b0a218595865ead3e399e3b29dd/modules/javafx.controls/src/main/java/javafx/scene/control/Labeled.java#L838-L841<https://urldefense.com/v3/__https:/github.com/openjdk/jfx/blob/8a5cb17ed6525b0a218595865ead3e399e3b29dd/modules/javafx.controls/src/main/java/javafx/scene/control/Labeled.java*L838-L841__;Iw!!ACWV5N9M2RV99hQ!O5PIY6RzCkXt8IZB_cJDcwbbQtpWdIn_eD5UALkoKFCGeCJeVYBBfkTd4q6zuLXtArNITv6DWEHxlHfs3Gv6skap9isYa3A$> always reports false
     *   Hence I tried to create a short self-contained TableView example to explore it further, see Gist https://gist.github.com/danielpeintner/9b561eb57261e8c5bc608f1346df74cf<https://urldefense.com/v3/__https:/gist.github.com/danielpeintner/9b561eb57261e8c5bc608f1346df74cf__;!!ACWV5N9M2RV99hQ!O5PIY6RzCkXt8IZB_cJDcwbbQtpWdIn_eD5UALkoKFCGeCJeVYBBfkTd4q6zuLXtArNITv6DWEHxlHfs3Gv6skapYpmRbZI$>
It still fails :-(
     *   The Email field in the table ideally should report "true" once the text entered exceeds the visible view. Somehow it fails... getWidth() and  prefWidth(-1) always return the same double value. Please try the Gist above to confirm.
e.g., edit cell and extend the email text to longer than column width --> results in System.out "Table-Email-Cell !isWrapText: 182.0 < 182.0 --> false"
     *   Hence I also added a *normal* MyLabel example which does work as intended
Maybe I miss something obvious but TableCells seem to be special Labeled instances and behave differently.

Thanks,

-- Daniel

[1] https://stackoverflow.com/a/52432862<https://urldefense.com/v3/__https:/stackoverflow.com/a/52432862__;!!ACWV5N9M2RV99hQ!O5PIY6RzCkXt8IZB_cJDcwbbQtpWdIn_eD5UALkoKFCGeCJeVYBBfkTd4q6zuLXtArNITv6DWEHxlHfs3Gv6skappYtR2cY$>


On Wed, Mar 6, 2024 at 6:10 PM Andy Goryachev <andy.goryachev at oracle.com<mailto:andy.goryachev at oracle.com>> wrote:
Dear Daniel:

Thank you for confirming the need for this enhancement.  Your case is covered by this ticket (I included a wrong ticket in my previous message by mistake, sorry):

JDK-8327483<https://bugs.openjdk.org/browse/JDK-8327483> TreeView: Allow for tooltip when cell text is truncated

My only concern is that this functionality theoretically can be achieved by the application code just as easy, since the solution does not use any internal APIs, as can be seen here: https://github.com/openjdk/jfx/pull/1389<https://urldefense.com/v3/__https:/github.com/openjdk/jfx/pull/1389__;!!ACWV5N9M2RV99hQ!LUwCrjMEKxlGC0k5v9-zO0Axw6TqddmMJM7_6onFdHOLL1eo5MDNu1lVj7grGquhgJdnqXX_eCyA7MGEMNyIivVMcBB9XfY$>

-andy


From: Daniel Peintner <daniel.peintner at gmail.com<mailto:daniel.peintner at gmail.com>>
Date: Tuesday, March 5, 2024 at 23:53
To: Andy Goryachev <andy.goryachev at oracle.com<mailto:andy.goryachev at oracle.com>>
Cc: openjfx-dev at openjdk.org<mailto:openjfx-dev at openjdk.org> <openjfx-dev at openjdk.org<mailto:openjfx-dev at openjdk.org>>
Subject: [External] : Re: Q: Labeled.textTruncated Property (RFE)
Hi Andy, all,

Thank you for the effort which I very much appreciate.
We have a similar use-case as the one mentioned in JDK-8205211.

We would like to show a Tooltip with the corresponding text once the text is shown with ellipsis for a TableCell. The *hacky* solution we are using is sketched in [1] and requires us to calculate the width again. Moreover, once different fonts come into the game it becomes even more brittle.

Having an easy (easier?) way to detect and observe whether a label is truncated is of importance for us and definitely improves the usability of JavaFX.

Thanks,

-- Daniel

[1] https://stackoverflow.com/a/52432862<https://urldefense.com/v3/__https:/stackoverflow.com/a/52432862__;!!ACWV5N9M2RV99hQ!LUwCrjMEKxlGC0k5v9-zO0Axw6TqddmMJM7_6onFdHOLL1eo5MDNu1lVj7grGquhgJdnqXX_eCyA7MGEMNyIivVMSbAOrZg$>

On Tue, Mar 5, 2024 at 10:15 PM Andy Goryachev <andy.goryachev at oracle.com<mailto:andy.goryachev at oracle.com>> wrote:
Dear colleagues:

Do you think a new property, ReadOnlyBooleanProperty textTruncated, should be added to the Labeled control?


On one hand, we do have a couple of tickets in JBS requesting that:


  *   JDK-8091891<https://bugs.openjdk.org/browse/JDK-8091891> TreeView: There is no tooltip available on truncated node
  *   JDK-8205211<https://bugs.openjdk.org/browse/JDK-8205211> Ability to show Tooltip only when text is shown with ellipsis (...)

On the other hand, this functionality can in theory be implemented at the application level, although the number of changes required might be uncomfortably large in the case of Tree/TreeTable/TableView.

JBS:

  *   JDK-8092102<https://bugs.openjdk.org/browse/JDK-8092102> Labeled: truncated property



Pull Request: https://github.com/openjdk/jfx/pull/1389<https://urldefense.com/v3/__https:/github.com/openjdk/jfx/pull/1389__;!!ACWV5N9M2RV99hQ!LUwCrjMEKxlGC0k5v9-zO0Axw6TqddmMJM7_6onFdHOLL1eo5MDNu1lVj7grGquhgJdnqXX_eCyA7MGEMNyIivVMcBB9XfY$>

What do you think?

-andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20240308/efdd21d3/attachment-0001.htm>


More information about the openjfx-dev mailing list