I want to be able to assign a hover color via CSS to a SplitPane Divider in JavaFX.
I am able to achive this by using the following CSS
.split-pane:horizontal > .split-pane-divider {
-fx-background-color: transparent;
}
.split-pane:horizontal > .split-pane-divider:hover {
-fx-background-color: lightblue;
}
However: since the divider is lagging behind the cursor, it causes a flickering effect, since the hover is triggered whenever the divider catches up to the cursor position – but while dragging slowly, it’s just a lot of flickering.
I want the hover color to be applied throughout any dragging of the divider.
Is there a way to achieve this via CSS? I tried .split-pane-divider:focused
and .split-pane-divider:selected
, but no luck 🙁
If not, is there any other way to achieve this?
Thanks!
2
Answers
The solution of Sai Dandem works, but the solution due to the comment of James_D makes it quite a bit simpler. Thanks to both of you!
For a general split-pane:
One way to fix this issue is by including a new pseudo state to the
SplitPane
(when the divider is in dragging mode). And include that state in the css same as hover state.The general idea is to set a custom pseudo state on mouse pressed filter and remove the state on mouse released. Setting the pseudo state on SplitPane will set on the divider as well, so you can set the style specifically for
.split-pane-divider:pressed
.Something like in the below demo:
Note: Maybe set a more unique pseudo state name, as
pressed
is already existing forButton
and may conflict if theSplitPane
hasButton
in its children hierarchy.