On Thu, 2 May 2024 22:10:24 GMT, Andy Goryachev <ango...@openjdk.org> wrote:
>> Adds **Labeled.textTruncated** property which indicates when the text is >> visually truncated (and the ellipsis string is inserted) in order to fit the >> available width. >> >> The new property reacts to changes in the following properties: >> - ellipsisString >> - font >> - height >> - text >> - width >> - wrapText >> >> I don't think it's worth creating a headful test (headless won't work) due >> to relative simplicity of the code. >> >> **Alternative** >> >> The desired functionality can be just as easily achieved on an application >> level, by adding a similar property to a subclass. What is the benefit of >> adding this functionality to the core? >> >> UPDATE 2024/03/07: 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. >> >> **See Also** >> >> * [JDK-8327483](https://bugs.openjdk.org/browse/JDK-8327483) TreeView: Allow >> for tooltip when cell text is truncated >> * [JDK-8205211](https://bugs.openjdk.org/browse/JDK-8205211) Ability to show >> Tooltip only when text is shown with ellipsis (...) > > Andy Goryachev has updated the pull request incrementally with one additional > commit since the last revision: > > using properties Here is a test showing the failure to detect truncated text. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.stage.Stage; public class TruncatedTest extends Application { private static final String clickMe = "Click me"; private static final String clickMeAgain = "Click me again, please"; @Override public void start(Stage stage) { stage.setTitle("Truncated Button Text (fails)"); var root = new HBox(10); Scene scene = new Scene(root, 600, 450); var button = new Button(clickMe); button.setPrefWidth(100); button.setOnAction(e -> { button.setText(clickMe.equals(button.getText()) ? clickMeAgain : clickMe); //System.err.println("truncated: " + button.isTextTruncated()); }); root.getChildren().add(button); var label = new Label(); label.textProperty().bind(button.textTruncatedProperty().asString()); root.getChildren().add(label); stage.setScene(scene); stage.show(); } public static void main(String[] args) { Application.launch(args); } } ------------- PR Comment: https://git.openjdk.org/jfx/pull/1389#issuecomment-2093024810