How can I change the font weight in a spreadsheet cell?

15 views
Skip to first unread message

Magnolia Sciences

unread,
Oct 30, 2022, 5:10:21 PM10/30/22
to ControlsFX
I'm trying to create text cells with the font weight set to bold.  I've tried setting the css style directly through the setStyle() API for SpreadsheetCell, and I've tried changing the -fx-font-weight property for the .spreadsheet-cell class in the spreadsheet CSS file.  Neither have worked.  Can someone tell me how to do this?  Thanks so much!

Mark Schmieder

unread,
Apr 1, 2023, 2:56:23 AM4/1/23
to ControlsFX
I haven't changed that specific CSS in SpreadsheetView but customized fonts in other parts of that API, so hopefully the CSS is consistent enough across that code base that the same approach would work.

Setting font attributes in JavaFX CSS can be a bit tricky as the "rules" don't always apply as expected. In some contexts, I find that only a very specific methodology works, whether individual tags, or in this case a combined tag with the attributes in a specific order. Here's my example tag:

-fx-font: italic bold 80.0% 'sans-serif';


My guess is that the fickelness of fonts in JavaFX CSS may relate to dynamic vs. static loading and lookup of custom fonts, derived fonts, system fonts, cross-platform fonts, etc. 

I also learned some hard lessons when I worked for a company a couple of years ago that wanted weird hard-to-read sci-fi custom fonts that required static startup loading and derivation, even using SVG. The specs were not correct, especially depending on specific Java updates, and only a few people on the web had figured out the tricks. The CSS stuff was involved in that case as well. 

There can be some order dependency, and resource lookup can be expensive and involve some deferred calls that might be thread-sensitive. Some API's may get around this by only supporting specific syntax for font attributes.

Reply all
Reply to author
Forward
0 new messages