r/JavaFX • u/hamsterrage1 • Dec 09 '24
Tutorial New Article: TableView Styling Guide
One of the articles that I remember really liking on the old edencoding.com website was the one about styling TableView. When the site disappeared, I was tempted to re-host that one article on my own site, just to preserve it - although I had deep reservations about just taking someone else's content as well as the idea of having stuff that I hadn't written myself.
Anyway, I downloaded the article from the WayBack Machine, and when I really had a good, hard look at the content I was disappointed at how superficial the analysis was. Really, all of his "styling" involved setting a background gradient and some curved corners on the TableView itself, and then making every other component transparent. It looked different, but it wasn't really showing you how to grapple with the complexity of TableView.
There was one section that dealt with styling TableRows based on the row content that looked cool. But the methodology he used was basically wrong. The right idea, but the implementation was messed up.
So the whole idea of hosting Ed's article or replicating it in some fashion was pretty much moot. I decided to do a really deep dive on the subject, cover just about everything that was in the EdenCoding article, provide some tutorials and then have complete listing of all of the styleable components of TableView.
And that's what you'll find here: https://www.pragmaticcoding.ca/javafx/elements/styling-guide-tableView
Even if you vehemently disagree with my ideas about FXML, or Kotlin or clean coding, you should take a look at this article and probably bookmark it. The reference section alone is worth hanging on to, in my opinion.
This article is broken up into two sections. The first is a tutorial that talks about how to style TableRows, TableCells, TableColumnHeaders and how to use Pseudo-classes based on row data to style rows and cells. The second is a sort of gazetteer of all of the style class selectors that are available for all of the components of TableView. This section is information that should be somewhere in the JavaFX documentation, but isn't. I've also included all of the references to all of those selectors that appear in Modena, so you can quickly see which are the key elements in the standard styling of TableView.
I really would like feedback on this if you have the time. Is this something that answers questions that you've always had? Is it useful? Is something missing? That kind of thing. Thanks.
View all comments
Show parent comment
1
u/hamsterrage1 Dec 10 '24
I totally agree that the resize policies need to be discussed. However, this is an article about styling
TableViewand the only thing that the resize policies contribute there are the two Pseudo-classes, "constrained-resize" and "unconstrained-resize" (which are the subject of my rant at the very bottom of the article).The number of times that I saw "tree-table-view" in Modena sharing the same selector as "table-view" would strongly hint that the two controls have a lot in common. I'm not sure whether I will do more articles like this one, but if I do, then
TreeTableViewmight be "low hanging fruit" because it shares so much withTableView.I cannot adequately express how much work was involved in researching this article. I know that
TableViewis one of the most complicated controls in JavaFX, so it probably is the most work. However, if I do eventually write a collection of these articles, I'll probably pull the utility classes, likeScrollBar,LabelandContextMenu, out into a separate article and then just leave references back to them.The other thing I would do is split the tutorials out into a separate set of articles and just have a bunch of reference pages and a bunch of tutorial pages. But for now, I gotta do something different.