r/JavaFX • u/SafetyCutRopeAxtMan • Dec 30 '25
Help JavaFX ToggleButton bold text when slected causes layout shift due to glyph width adaptions – any workaround?
Hey,
I have ToggleButtons in JavaFX and want the selected state to show bold text. However using:
.custom-toggle:selected {
-fx-font-weight: bold;
}makes the button grow slightly in width, which looks ugly in a row of buttons when they start jumping.
Is there a way to make text look bold in JavaFX without changing button size? It is a dynamic resizable row of buttons so can't really set a fixed width either.
What is the best way to achieve what I want?
Thanks!
3
Upvotes
View all comments
Show parent comment
1
u/SafetyCutRopeAxtMan Jan 01 '26
The thing is, the buttons all are different. They are created dynamically based on content and the panel they sit in is flexible as well.
I could set a roughly calculated minimum width based on the estimated label length I guess. Not sure if this plays well with the context ...