Styling JavaFX Popover

断了今生、忘了曾经 提交于 2019-11-27 08:29:23

问题


I need to style a Popover from ControlsFX, but am failing to do so.

I have my own xxx.css stylesheet that I add to a scene, and I've (obviously) successfully styling many JavaFX Controls...

I have set this in the stylesheet (copied and modified from popover.css in ControlsFX):

.popover > .border {
    -fx-stroke: linear-gradient(to bottom, rgba(0,0,0, .3), rgba(0, 0, 0, .7));
    -fx-stroke-width: 0.5;
    -fx-fill: rgba(30 , 30, 30, .95);
    -fx-effect: dropshadow(gaussian, rgba(0,0,0,.2), 10.0, 0.5, 2.0, 2.0);
}

But the Popover never gets the border style. How do I get the Popover to pick the style up?


回答1:


Since the PopOver is displayed in a different window, you can't set your style on the primary scene, but on the PopOvercontrol.

If you look at how the style is applied to the control in its skin class PopOverSkin:

stackPane = new StackPane();
stackPane.getStylesheets().add(
            PopOver.class.getResource("popover.css").toExternalForm());
stackPane.getStyleClass().add("popover"); 

where this stackPane can be accessed with:

@Override
public Node getNode() {
    return stackPane;
}

you just need to add your style sheets to that stack pane, right after you have access to the skin, that is, when the popOver is shown:

popOver.show(...);

((Parent)popOver.getSkin().getNode()).getStylesheets()
    .add(getClass().getResource("MyPopOver.css").toExternalForm());


来源:https://stackoverflow.com/questions/27513459/styling-javafx-popover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!