JavaFx CSS style: Change left and right of selected - java

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?

Related

There is a way to change text Selection Handle cursor style on javafx mobile?

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:

JavaFX ListView - remove spacing / padding / margin between cells

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;
}

Change selection color of a JavaFX TreeTableView

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*/
}

Custom TableCell Border

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.

How to make a moving dashed border with CSS?

I'm displaying a dashed border around an input text element with:
border: 1px dashed black;
Can I somehow define an "offset" to tell the browser where to start with the border?
My goal is to define a timer, and alter the offset of the dashed border (using java GWT element.setAttribute()), so that the simulation of a clockwise-moving dashed border results.
Is there any existing offset for borders with css?
There is a somewhat convoluted workaround to achieve a similar effect using an animated .gif as the background of a div, with whatever content you wanted "bordered" placed in a second div nested within the first with a 1px margin.
The animated .gif should be a small square (8px x 8px) with 3px-wide diagonal lines moving across it from left to right (you can adjust the sizes to adjust the width of the lines). When only a pixel's width or height of this image is visible, it appears to be a moving dashed border.
This technique is detailed here by Matthew Taylor at his blog: http://matthewjamestaylor.com/blog/animated-photoshop-selection-on-a-web-page.

Categories