This content has been marked as final. Show 3 replies
Well, I have a way, but I think there should be an easier way.
1. Set the text of the TableColumn to the text you want to appear in the popup menu.
2. Set the graphic of the TableColumn to a new Text("...") with the text you want in the table header
3. Use CSS (see your previous thread) to set the -fx-content-display on the tabel header to "graphic-only"
If you want an image as well as text in the table header, you could try setting the graphic to an HBox and filling the HBox with an ImageView and Text (for example).
This loses some of the default behavior of the table header, too; for example there is no automatic ellipsis if the table column is too narrow to display the text.
Someone else may (surely) have a better solution...
All the header functionality is still in place even with a compete custom graphics in the header! Sorting is available, dragging is available and I don't use ellipsis so I didn't lose any functionality !
And it's not hard at all for my taste. Hard would be to re-write half fx to achieve control over table header :)
Thank you very much !
It's not so much that it's hard, it's just that it creates counter-intuitive (and thus hard to maintain) code. The text property on the TableColumn should be the text that's displayed in the column header: this makes intuitive sense. You now have the text property controlling something different. The code that overrides the default behavior (i.e. prevents the text property from appearing in the column header) is hidden away in a (probably fairly obscure) line in your css file. If this were my code, I can imagine coming back to this in 6 months' time and having no idea how it worked. (So, obviously, you'll need to document the code carefully; but my point is that good code should be self-documenting.)