I have a Label in a GridPane in a TitledPane. I want it to downsize stepwise by 0.05em if it is overrun so the three dots (\"Long Labe...\") dont show up -> \"Long Label\" i
Solution:
fontVerkleinerung(lblXYZ); //call resizing at beginning
lblXYZ.styleProperty().addListener((observable, oldV, newV) -> {
fontVerkleinerung(lblXYZ); //check size again if resized
});
private void fontVerkleinerung(Label label) {
Platform.runLater(() -> {
tpBounds = tPane.getBoundsInLocal();
if (label.getBoundsInLocal().getWidth()>tpBounds.getWidth() && !fontSizeFits) {
fontSize = fontSize-0.02;
label.setStyle("-fx-font-size: "+fontSize+"em;");
}
if (label.getBoundsInLocal().getWidth()<=tpBounds.getWidth() && !fontSizeFits) {
fontSizeFits = true;
}
});
}
This workaround is not 100% satisfying, the GUI is suffering due to the slow graphic updaterate on label.setStyle("...");
It takes a few ms till the styleProperty-listener kicks in.
I tried to fix this for a few weeks now, always found a probably-solution but it didn't work. I hope somebody profits from this post.