Is there a z-index for the TableView Selection in JavaFx - javafx

How can I set the z-index for the selection in a TableView. Some rows are conditional formatted and the formatting is overlying the Selection.
Screenshot of what I mean. Take a look at the last row!
Here is my RowFactory:
public void createRowFactory(){
final String CSS_OUTOFSTOCK = "outofstock";
mainTableView.setRowFactory(row -> {
return new TableRow<Artikel>(){
#Override
protected void updateItem(Artikel article, boolean empty){
super.updateItem(article, empty);
getStyleClass().removeAll(CSS_OUTOFSTOCK);
if(article != null){
if(article.mengeLagerProperty().get() == 0){
getStyleClass().add(CSS_OUTOFSTOCK);
}
}
}
};
});
}
And that's my CSS
.outofstock{
-fx-background-color: rgba(255, 159, 160, .4);
}

Here's how the default CSS from modena works for table rows and table cells:
The background color of a table row is set as a nested background depending on two looked-up colors:
.table-row-cell {
-fx-background-color: -fx-table-cell-border-color, -fx-background;
}
The insets are set as
.table-row-cell {
-fx-background-insets: 0, 0 0 1 0;
}
so the effect of this is that there is a 1-pixel border using -fx-table-cell-border-color along the bottom, and the rest of the row is colored in -fx-background.
-fx-background itself is defined as
.table-row-cell {
-fx-background: -fx-control-inner-background;
}
and overridden for odd rows with
.table-row-cell:odd {
-fx-background: -fx-control-inner-background-alt;
}
to give the striped effect.
Individual cells have no background color (so the background color of the row is visible), but they define a 1-pixel border on the right of each cell with
.table-cell {
-fx-background-color: null;
-fx-border-color: transparent -fx-table-cell-border-color transparent transparent;
}
When the row is selected, the looked-up color -fx-background is modified to take the value of a different looked-up color (essentially the bright blue, by default). Similarly the border color of the cell is modified to a lighter version of that color:
.table-row-cell:filled:selected {
-fx-background: -fx-selection-bar;
-fx-table-cell-border-color: derive(-fx-selection-bar, 20%);
}
Since you just change the background color of the table row directly, you lose the "nested background" (i.e. the border at the bottom of the row). The individual cells still draw their borders, which are either an off-white (if the row is not selected), or a blue (if the row is selected).
So you probably want to redefine each of the key looked-up colors for your CSS class, to inherit all the basic functionality (selection, borders, etc). For example:
.outofstock {
-fx-control-inner-background: rgba(255, 159, 160, .4);
-fx-selection-bar: rgba(255, 79, 80, .4);
}
You could also redefine -fx-table-cell-border-color if you want, though the default is quite neutral: #ececec.

I don't really understand the accepted answer despite reading it 1000x. It's overly complicated and fails to provide the exact css to get this to work. -fx-control-inner-background does nothing to set the background color of a cell when a custom cell factory is defined.
Here is simple css that I found works.
.table-row-cell:selected .outofstock {
-fx-background-color: -fx-accent;
-fx-border-color: -fx-accent;
}
-fx-accent is defined in .root (checkout javafx caspian.css). Its the color that defines what the table row selection is.

Related

JavaFX TreeTableView Css for unfocused selected line

I have a problem with CSS on TreeTableView.
For TableView when I define CSS like this :
.table-row-cell:selected{
-fx-background-color: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
-fx-text-fill: white;
}
The selected rows have text in white even if I click out of the table
For TreeTableView I have defined CSS like this :
.tree-table-row-cell:selected{
-fx-background-color: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
-fx-text-fill: white;
}
The selected rows have text in white but when I click out of the table the text change to black
Does someone know how can I solve this ?
Thank you
Try setting the text fill on the cells themselves, instead of the row cells:
.tree-table-row-cell:selected{
-fx-background-color: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
}
.tree-table-row-cell:selected .tree-table-cell,
.tree-table-cell:selected {
-fx-text-fill: white;
}
You probably also want
.tree-table-row-cell:selected .tree-disclosure-node .arrow {
-fx-background-color: white ;
}
For a slightly different approach:
The default behavior of the modena stylesheet is to set the text fill to a "looked up color" called -fx-text-background-color. This is set to a "ladder", which is a function based on the value of another looked-up color called -fx-background. The background color of the rows and cells is defined in terms of -fx-background.
The way the "ladder" works is if the intensity of -fx-background is less than 45%, the ladder evaluates to -fx-light-text-color (white), between 46% and 59% it evaluates to -fx-dark-text-color (black) and above that to -fx-mid-text-color (grey).
So typically, you can simply change -fx-background (instead of -fx-background-color) and the text will change to something appropriate:
.tree-table-row-cell:selected{
-fx-background: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
}
In your case, this won't quite give you what you want. The color you chose as the background isn't dark enough to trigger the light text color; the intensity is about 58%, so it evaluates to black.
If you use a darker background, say #d1531f, then you see the white text with no additional changes.
You can fix this by adjusting the ladder itself so the intensity thresholds are different:
.tree-table-row-cell:selected{
-fx-background: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
-fx-text-background-color: ladder(
-fx-background,
-fx-light-text-color 60%,
-fx-dark-text-color 61%,
-fx-dark-text-color 69%,
-fx-mid-text-color 70%
);
}
or perhaps just by bypassing the ladder entirely and setting -fx-text-background-color directly to the light text color:
.tree-table-row-cell:selected{
-fx-background: #f1734f;
-fx-background-insets: 0;
-fx-background-radius: 1;
-fx-table-cell-border-color: white;
-fx-text-background-color: -fx-light-text-color;
}
This is more complex (perhaps) but is more in the style of the default CSS. It works with the cells without explicitly having to change the CSS for those (basically, looked-up colors are inherited), and the disclosure arrow automatically has the same color as the text.

Highlight top of a JavaFX TableRow with css

I'm trying to figure out the CSS for highlighting the top of a TableRow. I'm using this for reordering rows so that anyone reordering them can tell where it will be inserted. Currently I've only been able to draw a rectangle around the row, but I just want the top line of that rectangle.
.table-row-cell.drag {
-fx-focus-color: #00a9d3;
-fx-faint-focus-color: #00a9d322;
-fx-highlight-fill: -fx-accent;
-fx-background-color:
-fx-focus-color,
-fx-control-inner-background,
-fx-faint-focus-color,
linear-gradient(from 0px 0px to 0px 5px, derive(-fx-control-inner-background, -9%), -fx-control-inner-background);
-fx-background-insets: -0.2, 1, -1.4, 3;
-fx-background-radius: 3, 2, 4, 0;
}
You could specify different -fx-background-insets for the sides. If one color should only appear on one side, the insets of the next color match the insets for the mark color except for the side that should be colored.
Furthermore I recommend using PseudoClass instead of a style class, since this way you don't need to make sure to not add a class multiple times.
final PseudoClass mark = PseudoClass.getPseudoClass("mark");
...
boolean marked = ...
row.pseudoClassStateChanged(mark, marked);
The following CSS is a bit simplified, but it should demonstrate the approach:
.table-row-cell:mark {
-fx-background-color: -fx-table-cell-border-color, red, -fx-background;
/* show red highlight of size 2 at the top */
-fx-background-insets: 0, 0 0 1 0, 2 0 1 0;
}

change the color of a button with a css sheet and keep the glow

I want to change the color of a button (javafx) to white with a css sheet. I already try with : -fx-background-color : #FFFFFF but I loose the glow of the button and I can't put it back with : -fx-focus-color: #039ED3; -fx-faint-focus-color: #039ED322;
And if I change the color with -fx-color: #FFFFFF, the color of the button is not white but grey...
Here, two pictures of the two situations: Button with glow but grey
Button without glow but white
Use -fx-body-color.
You may want to choose different colors for hovered and armed buttons from a css stylesheet.
.button {
-fx-body-color: white;
}
.button:armed:hover {
-fx-body-color: #CCCCCC;
}
.button:hover {
-fx-body-color: #DDDDDD;
}

javafx treeview css how to add line after every parent node

In JavaFx treeView, how to add line after every parent node ? Please refer to my code below. I tried to select only child node in css and apply border with top transparent and select only parent node and apply border with bottom transparent.
.tree-view .tree-cell {
-fx-indent: 0;
}
.tree-cell:filled:selected {
-fx-border-color: transparent #111111 #111111 #111111;
-fx-background-color: rgb(100,100,100,0.2);
}
.tree-cell:hover .highlight-on-hover { /* not working, this is where I need some help */
-fx-border-color: transparent #111111 #111111 #111111;
-fx-background-color: rgb(100,100,100,0.2);
}
This is causing a line in between my parent and child node which I want to eliminate. How to do that ?

JavaFX - CSS styling listview

I have a ListView and want the following:
Odd rows with white background color;
ListView: when mouse over an item, highlight with a blue shade;
ListView: when an item is selected, paint it with a gradient;
ListView: when focus is lost from ListView, selected item should be painted with gradient;
ListView: all items will start with text-fill black. But on mouse over and/or selected it will change to white.
That's my code. It's working fine, except for the even rows: on mouse over, it highlight in white. So, the text's white and can't be showed. What's wrong with it?
.list-cell:filled:selected:focused, .list-cell:filled:selected {
-fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%);
-fx-text-fill: white;
}
.list-cell:odd {
-fx-cell-hover-color: #0093ff;
-fx-background-color: white;
}
.list-cell:filled:hover {
-fx-cell-hover-color: #0093ff;
-fx-text-fill: white;
}
Thanks in advance.
EDIT:
Slightly changing your css:
.list-cell:filled:selected:focused, .list-cell:filled:selected {
-fx-background-color: linear-gradient(#328BDB 0%, #207BCF 25%, #1973C9 75%, #0A65BF 100%);
-fx-text-fill: white;
}
.list-cell:even { /* <=== changed to even */
-fx-background-color: white;
}
.list-cell:filled:hover {
-fx-background-color: #0093ff;
-fx-text-fill: white;
}
This css produces the following presentation:
Does this give what you expect?
I changed odd to even. The first cell is even, because its index value is 0 (zero). Also -fx-cell-hover-color is not valid. I changed it to -fx-background-color where needed or removed it.
Original text: (note that this has different interpretation of odd/even)
My take would be this:
(I included your requirements in a numbered list for reference in the css. I also made the gradient more obvious and added a green background for even cells.)
/*
1. Odd rows with white background color;
2. ListView: when mouse over an item, highlight with a blue shade;
3. ListView: when an item is selected, paint it with a gradient;
4. ListView: when focus is lost from ListView, selected item should be painted with gradient;
5. ListView: all items will start with text-fill black. But on mouse over and/or selected it will change to white.
*/
.list-cell:filled:selected:focused, .list-cell:filled:selected {
/* 3:, 4: */
-fx-background-color: linear-gradient(#333 0%, #777 25%, #aaa 75%, #eee 100%);
-fx-text-fill: white; /* 5 */
}
.list-cell { -fx-text-fill: black; /* 5 */ }
.list-cell:odd { -fx-background-color: white; /* 1 */ }
.list-cell:even { -fx-background-color: #8f8; /* for information */ }
.list-cell:filled:hover {
-fx-background-color: #00f; /* 2 */
-fx-text-fill: white; /* 5 */
}
This leads to this rendering:

Resources