1

By default, TableView shows colors for absent rows too:

enter image description here

Example is taken from here and a table has only 5 rows. Nevertheless, visually it still displays interleaving color for 6ht, 7th and so on rows.

How to avoid this? I wan't it be visible, that rows are ended.

Dims
  • 47,675
  • 117
  • 331
  • 600
  • 1
    Do you just want to remove the styling or do you intend to adjust the height as well? – ItachiUchiha May 05 '16 at 12:19
  • Possible duplicate of [TableView: adjust number of visible rows](http://stackoverflow.com/questions/26298337/tableview-adjust-number-of-visible-rows) – ItachiUchiha May 05 '16 at 17:50
  • I want to remove these rows so that no any styling can re-appear them. They should be absent completely. – Dims May 06 '16 at 07:32
  • "Duplicate" question has no accepted answer as you see, i.e. it is providing workarounds but not an answer. – Dims May 06 '16 at 07:33

1 Answers1

3

Use the empty pseudo class (see Cell CSS reference) to set the background color of those rows from css:

E.g.

.table-row-cell:empty {
    -fx-background-color: transparent;
}

In case you use CSS to style odd/even cells yourself, you can simply add the :filled pseudoclass to all those selectors to only make them applicable to non-empty cells (assuming those selectors are for Cells only). E.g.:

.table-row-cell:empty {
    -fx-background-color: transparent;
}

.table-row-cell:odd:filled {
    -fx-background-color: red;
}

.table-row-cell:even:filled {
    -fx-background-color: lightblue;
}

Or simply use more concrete selectors by using the selectors applying to table rows plus the :empty selector:

.table-row-cell:empty:odd, .table-row-cell:empty:even {
    -fx-background-color: transparent;
}

.table-row-cell:odd {
    -fx-background-color: red;
}

.table-row-cell:even {
    -fx-background-color: lightblue;
}
fabian
  • 80,457
  • 12
  • 86
  • 114
  • How can I sure it won't interfere with odd-even styling? – Dims May 05 '16 at 13:38
  • @Dims: What do you mean by "interfere" with odd-even styling? Do you want the color to differ(ob be the same as) the one of the last row or something. Are you uncertain whether if the selector has a higher priority than `:odd` and `:even` selectors? Or something else??? – fabian May 05 '16 at 13:54
  • @Dims: added 2 alternatives for that to my answer. I'd recommend using `:filled`, if possible. – fabian May 05 '16 at 16:58
  • 1
    You can also consider setting the "looked-up colors" used by modena. This removes ambiguity too: `.table-row-cell { -fx-control-inner-background: lightblue ; -fx-control-inner-background-alt: red ; }` and `.table-row-cell:empty { -fx-background-color: transparent ;}` – James_D May 05 '16 at 17:37
  • I want to provide a control with which end-user will be unable to style empty rows at all. They should really absent, not just colored out. – Dims May 06 '16 at 07:36
  • @Dims: Adding those empty rows is a "core" behavior of the default skin of `TableView`. Removing those rows probably requires you to modify (if not reimplement) the `Skin`... Good luck with that. Personally I haven't messed around with skins yet... – fabian May 06 '16 at 07:52