I like the styling of the bars that comes with using -fx-bar-fill in my CSS code. However, there is a situation which calls for a bit of customization (I need one of my series' bars to have an striped pattern instead of merely a color). However, without using -fx-bar-fill the bars loose a number of properties beyond just the color, causing them to not match.
What is it exactly that -fx-bar-fill does? What are the individual properties such that I can re-apply them manually, if possible?
With -fx-bar-fill, you only specify a single color. From there it seems to then add:
(Working)
A linear gradient based on the color specified (-fx-background-color: linear-gradient())
A border color slightly darker than the color of specified (-fx-border-color: linear-gradient())
(Not fully working)
An inner glow linear gradient slightly lighter than the color specified (-fx-effect: innershadow(three-pass-box,#00FF00,2,0,0,0);?)
I can't seem to fully replicate the inner glow on a gradient. Is there another way to do it? Are there any other effects in -fx-bar-fill which I might be missing?
Zoomed version:
-fx-bar-fill is not a property, but a looked-up color (essentially a CSS variable that holds a color value; see the CSS documentation for the color type and scroll down just past the table of predefined color-swatches).
This looked-up color is used in setting the -fx-background-color property of the bars in the bar chart, which are implemented as regions. From the source code for modena.css:
.chart-bar {
-fx-bar-fill: CHART_COLOR_1;
-fx-background-color: linear-gradient(to right,
derive(-fx-bar-fill, -4%),
derive(-fx-bar-fill, -1%),
derive(-fx-bar-fill, 0%),
derive(-fx-bar-fill, -1%),
derive(-fx-bar-fill, -6%)
);
-fx-background-insets: 0;
}
So this sets the value of -fx-bar-fill to another looked-up color, CHART_COLOR_1 (more in a moment), and then defines the background color of the bars in the bar chart to a (very subtle) linear gradient whose color stops are based on its value.
Colors for bars in other series are set differently by redefining the value of -fx-bar-fill for bars in those other series:
.default-color0.chart-bar { -fx-bar-fill: CHART_COLOR_1; }
.default-color1.chart-bar { -fx-bar-fill: CHART_COLOR_2; }
.default-color2.chart-bar { -fx-bar-fill: CHART_COLOR_3; }
.default-color3.chart-bar { -fx-bar-fill: CHART_COLOR_4; }
.default-color4.chart-bar { -fx-bar-fill: CHART_COLOR_5; }
.default-color5.chart-bar { -fx-bar-fill: CHART_COLOR_6; }
.default-color6.chart-bar { -fx-bar-fill: CHART_COLOR_7; }
.default-color7.chart-bar { -fx-bar-fill: CHART_COLOR_8; }
and those individual colors are defined as
CHART_COLOR_1: #f3622d;
CHART_COLOR_2: #fba71b;
CHART_COLOR_3: #57b757;
CHART_COLOR_4: #41a9c9;
CHART_COLOR_5: #4258c9;
CHART_COLOR_6: #9a42c8;
CHART_COLOR_7: #c84164;
CHART_COLOR_8: #888888;
So the net result is that, for the first series, the bar starts at the left edge with a color 4% darker than #f3622d, lightens (in a non-linear way) to #f3622d at the center, and then darkens by 6% to the right edge.
James_D led me to the answer with his post above. I would only add (for the record) that his java version (8_u60) is newer than mine (7_u75), which uses a different CSS file for styling the bar charts. To provide the answer specific to my java version (i.e. to get my exact result in terms of how the bars are styled for me), the CSS for the -fx-bar-fill is as follows:
.chart-bar {
-fx-bar-fill: #22bad9;
-fx-background-color: linear-gradient(derive(-fx-bar-fill,-30%), derive(-fx-bar-fill,-40%)),
linear-gradient(derive(-fx-bar-fill,80%), derive(-fx-bar-fill, 0%)),
linear-gradient(derive(-fx-bar-fill,30%), derive(-fx-bar-fill,-10%));
-fx-background-insets: 0,1,2;
-fx-background-radius: 5 5 0 0, 4 4 0 0, 3 3 0 0;
}
Related
I'm not sure this css problem or something else. Javafx doesn't have css styling for text selection cursor because maybe javafx not designed to be a mobile application. When I'm searching about it. I found css styling for input caret. Like this but that's not the case for the problem i have. Any help would be appreciated.
Here there sample what i want.
Here is my javafx project after porting into android
Yes, there is a way.
JavaFX's built in controls TextField and TextArea define the caret node, using caretHandle, selectionHandle1, selectionHandle2 stackpanes with CSS style classes caret-handle and selection-handle.
This is still valid in the latest JavaFX version:
caretHandle.getStyleClass().setAll("caret-handle");
selectionHandle1.getStyleClass().setAll("selection-handle");
selectionHandle2.getStyleClass().setAll("selection-handle");
On a regular desktop platform, you would use modena.css, where the caret-handle, selection-handle style classes are not used.
However in other platforms like Android, where embedded.css or touch.css are used, these do use the style classes:
.caret-handle {
-fx-background-color: transparent,
black /*#ACACAC*/,
linear-gradient(to bottom, #AFAFAF 0%, #DFDFDF 100%);
-fx-shape: "M11.974,2.579L20,12.358V20H4V12.356L11.974,2.579z";
...
The path in -fx-shape sets the shape you have posted in your picture:
Being set by CSS, you can always override the shape with your own.
You just need to add it to your CSS file, like:
.caret-handle {
-fx-background-color: blue;
-fx-shape: "M 100,100 m -75,0 a 75,75 0 1,0 150,0 a 75,75 0 1,0 -150,0z";
-fx-background-insets: 0;
-fx-padding: 0.5em;
}
that will give you:
As I have custom cells for a particular ListView, I have big trouble to understand how to to remove the "natural" sort of margin / spacing there is between each cells, and, even worse, on the right and left sides of said cells.
Here's an example:
]1
As you can see, I use a color to bring out each cell. You cannot see the space at the end of the cells (on their right side), because I need to scroll, but you can trust me, the white space is equal on each side (bigger on the left & right, though...) which is not normal as I have specifically designed these cells so that their width is as large as the ListView so that there is no need to use horizontal scrolling. My issue kinds of defeat my purpouse...
Each cell consists of one AnchorPane with the image and the one label.
The AnchorPane is painted in yellow (-fx-background-color: yellow;).
And as you can clearly see, there is these white spaces all around the cells.
FYI, here I am using JavaFX 8 / 2.2 SDK but I intend to use JFoenix JFXListView & JFXListCell. However, the spacing is even worse using those.
Strange point: I also painted the ListViewin green, but such color is nowhere. to be seen. I guess all the cells (and the empty one) overwrites the ListView content, so it would make sense not to see its background. However, this means the cells are somehow "corrupted" since white spaces are "added" all around my cells.
I have tried to set padding to 0 for everything but in vain.
Finally, in the onUpdateItem method, I do call the super method and when the cell is not flagged as empty, I set the graphic to the aforementioned AnchorPane otherwise I set it to null, which is clearly consistent to my screenshot.
Thanks for the help !
If you look at the default CSS stylesheet for JavaFX, modena.css, you'll see:
.list-cell {
-fx-padding: 0.25em 0.583em 0.25em 0.583em; /* 3 7 3 7 */
}
This is where the padding for the ListCells is coming from. To remove this padding simply add your own stylesheet which contains:
.list-cell {
-fx-padding: 0px;
}
Or call setStyle for each of your ListCells:
setStyle("-fx-padding: 0px;");
The second option would best be done by using a custom cell factory.
listView.setCellFactory(v -> new ListCell<>() {
{
setStyle("-fx-padding: 0px");
}
#Override
protected void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
// your custom display logic
}
}
});
Also, after some quick testing with JFoenix it looks like using the above will also work for JFXListCell; though you have to be careful about overriding updateItem because JFXListCell does a lot in its implementation.
I set the red background of the cell as default to make sure that the artifacts I see between cells are in fact created by the .list-cell.
No matter how hard I tried, I could not get rid of it, even with the padding 0px. The red background was still visible every other cell in my case.
I suppose, it is a rounding error...
So, the only thing that worked was using a negative padding to remove any spacing | padding | margin between cells.
.list-cell{
-fx-font-weight: normal;
-fx-text-fill: white;
-fx-padding: -1px;
-fx-background-color: red;
}
I'm having a little trouble regarding FX, CSS and the TreeTableView.
I have cells containing blue Hyperlinks. Now if the cell is selected, the background becomes blue and thus the link is practically invisible. I'd now like to change the background color of selected cells using Stylesheets.
For TreeView the following works fine:
.tree-view .tree-cell:selected{
-fx-background-color: green;
}
So analogously I tried:
.tree-table-view .tree-table-cell:selected{
-fx-background-color: green;
}
But this had no effect.
Surprisingly though I was able to change the general background color with this:
.tree-table-view .tree-table-cell{
-fx-background-color: yellow;
}
The cells were now all yellow but this is seems to override the default selection pattern as now even selected rows had a yellow background.
For me it seems as if the state selector does not apply to TreeTableView cells but I have no clue how to achieve this another way.
I also tried this with the Example 15-2 from the JavaFX documentation, getting the same unsatisfying result.
I was not able to find any solution on the web as all questions seem to regard TreeViews or TableViews but not the combined TreeTableView. So any hint or link to the right doc would be very helpful!
Thanks in advance!
P.S:
I am aware that one could cirumvent the problem by changing the color of the Hyperlink but there must be a way to change the cell's color, right?
You can use the .tree-table-row-cell selector with the -fx-background-color property you mentioned:
.tree-table-row-cell:selected {
-fx-background-color: green;
}
and you can also change the border color to better fit to the filling color:
.tree-table-row-cell:selected {
-fx-background-color: green;
-fx-table-cell-border-color: green;
}
You may apply more styles to the underlying table cell by using:
.tree-table-row-cell:selected > .tree-table-cell{
/*enter style rules here*/
}
So in my Java Application I have a grid pane with a time table of various names.
To change the color of the one my mouse is hovering over I do this:
.hours_grid_cell_pane:hover{
-fx-background-color: #ffff00;
-fx-border-color: #000000;
}
This is pretty simple. I want to know how I do the same thing to all the cells to the left, right, top, and bottom of the one I'm hovered over. Essentially forming big where my mouse is.
I've tried
.hours_grid_cell_pane:hover:left
and
.hours_grid_cell_pane:left
but that doesn't work. Is there any way to do this?
If you look in modena.css you can see how the border of the default TableCell is specified:
.table-cell {
...
-fx-border-color: transparent -fx-table-cell-border-color transparent transparent;
...
}
As you can see the border is transparent apart from the right side that has the color specified by -fx-table-cell-border-color.
I would like the border on the right side to have two different colours. -fx-table-cell-border-color for all the pixels apart from the very bottom pixel that I would like to be red.
Is there anyway to specify that a border side is made up of more than one colour?
What about this:
.table-cell {
-fx-border-color: transparent
linear-gradient(to bottom, -fx-table-cell-border-color 95%,
red 95%)
transparent
transparent;
}
Note the 95%, depending on the height of the rows you can increase it to 95%+.
I've included this (scaled) pic of two tables, one with regular css (left), one with this css (right). The red pixel is just at the corner.