JavaFX: Hide Slider/Divider of the SplitPane

2019-06-16 01:37发布

I have a JavaFX application with a SplitPane. I want do hide the Slider/Divider of SplitPane. How can I do this?

Greetings from Germany (so sorry for my english)

Julian

6条回答
来,给爷笑一个
2楼-- · 2019-06-16 02:11

In caspian.css, you will see

/* horizontal the two nodes are placed to the left/right of each other. */
.split-pane:horizontal > * > .split-pane-divider {
   -fx-border-color: transparent -fx-box-border transparent #BBBBBB;
   -fx-background-color: transparent, -fx-inner-border-horizontal;
   -fx-background-insets: 0, 0 1 0 1;
}

/* vertical the two nodes are placed on top of each other. */
.split-pane:vertical > * > .split-pane-divider {
   -fx-border-color:  #BBBBBB transparent -fx-box-border transparent;
   -fx-background-color: transparent, -fx-inner-border;
   -fx-background-insets: 0, 1 0 1 0;
}

I am using a vertical one, so I overrided the vertical one in my css as following:

.split-pane:vertical > * > .split-pane-divider {
   -fx-border-color:  transparent;
   -fx-background-color: transparent;
   -fx-background-insets: 0;
}

And it works. If you want to hide the grabbers too (e.g. I did not hide it, it seems nice), I think the following rule might do the trick:

.split-pane *.vertical-grabber {
    -fx-padding: 0;
    -fx-background-color: transparent;
    -fx-background-insets: 0;
    -fx-shape: " ";
}

I hope it helps.

查看更多
3楼-- · 2019-06-16 02:13

Late, but this is how to do it correctly instead of working around it using CSS:

for (Node node : splitPane.lookupAll(".split-pane-divider")) {
    node.setVisible(false);
}
查看更多
Melony?
4楼-- · 2019-06-16 02:16

These other answers still left a thin gray bar so in my CSS I added:

.split-pane-divider {
   -fx-background-color: transparent;
}
查看更多
家丑人穷心不美
5楼-- · 2019-06-16 02:18

SplitPane.Divider doesn't inherit from Node, therefore it hasn't a disableProperty.

If you need to have a split pane to be resized JUST from the code, you can skin the divider through CSS to be invisible and with a size near 0.

Otherwise use AnchorPane's nested into a VBox

查看更多
该账号已被封号
6楼-- · 2019-06-16 02:26

Another note:

The divider shows between children in the Split Pane's list of items. If your split pane only has one item in it, no divider will appear. If your split pane has 3 items, 2 dividers appear. If you do not need a divider, you may not need an item in the split pane all together.

查看更多
来,给爷笑一个
7楼-- · 2019-06-16 02:32

Its a little different in Java FX8 (modena style):

.split-pane *.split-pane-divider {
    -fx-padding: 0 1 0 1;
}
查看更多
登录 后发表回答