-
1. Re: How to customize background color of a table column?
lngrvr Sep 4, 2013 2:57 PM (in response to lngrvr)Deal all,
No one can help me?
Thanks,
Jason
-
2. Re: How to customize background color of a table column?
lngrvr Sep 4, 2013 3:21 PM (in response to lngrvr)1 person found this helpful@Override public void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
setStyle("-fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border,
-fx-selection-bar;-fx-alignment: CENTER_RIGHT;-fx-padding:0 3 0 0;");
...
}
Well. It is solved by using above code. The look-feel is acceptable, but the style code is too long and strange.
-
3. Re: How to customize background color of a table column?
James_D Sep 4, 2013 5:56 PM (in response to lngrvr)It's probably better (makes more readable code, and better separation of concerns) to just set a style class on your TableCell, then actually define the styles in an external style sheet.
Something like:
@Override public void updateItem(Object item, boolean empty) { super.updateItem(item, empty); setText(item.toString()); getStyleClass().add("special-table-column"); }
and then in an external style sheet
.special-table-column { -fx-background-color: -fx-focus-color, -fx-cell-focus-inner-border, -fx-selection-bar ; -fx-padding: 0 3 0 0 ; -fx-alignment: center-right ; }
Obviously you can replace "special-table-column" with something that logically represents what you're doing.
-
4. Re: How to customize background color of a table column?
lngrvr Sep 5, 2013 2:33 AM (in response to James_D)Thank you!
-
5. Re: How to customize background color of a table column?
jsmith Sep 5, 2013 9:01 PM (in response to James_D)In the updateItem call, first do a contains check before adding the style class.
if (!getStyleClass().contains("special-table-column")) {
getStyleClass().add("special-table-column");
}
updateItem can be called many times for a single cell, so if you keep adding style classes each time updateItem is called, you will end up with a memory leak (and possibly other undesirable consequences).
-
6. Re: How to customize background color of a table column?
James_D Sep 6, 2013 12:24 AM (in response to jsmith)Yes, good call.