Styling JavaFX Popover

后端 未结 1 853
南方客
南方客 2020-12-12 04:25

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 stylin

相关标签:
1条回答
  • 2020-12-12 05:13

    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());
    
    0 讨论(0)
提交回复
热议问题