P
P
postya2019-06-14 15:49:34
Java
postya, 2019-06-14 15:49:34

How to find out if there is an ellipsis in the text of the label?

Application in JavaFX, I have a label. It will contain different text. When the text becomes larger than the size of the label, it is cut off and 3 dots (ellipsis) appear in place of the last characters.
I need that when the text goes beyond the label and elipsis appears, the font size of the text decreases, for example by 30%, so that the text fits completely into the label.
How do I know if the label has ellipsis?
How can you get ellipsis?
I tried instead of 3 dots ellipsis to replace with other characters, and then use the method contains()to check if these characters are in the text of the label, but Java does not find these characters, it seems that the ellipsis characters are not available to the method. contains()
Perhaps because Java does not replace the truncated text with ellipsis , and imposes on top of it

@FXML private Label label;

if(label.contains("...") {
label.setFont(Font.font("Serif", 55));
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2019-06-14
kuzmin @sergueik

try

label.setOnMouseEntered(new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent e) {
            System.err.println(String.format("The label.bounds: %.2f %.2f,
                Math.floor(label.getBoundsInLocal().getWidth()),
                Math.floor(label.getBoundsInLocal().getHeight())));

you will see something like
scale depending on the size
label.setScaleX(0.82);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question