Applying CSS file to JavaFX WebView

前端 未结 2 1587
南旧
南旧 2020-12-10 03:53

I am trying to apply a CSS file to a JavaFX WebView object. From what I\'ve read, this should do the trick, but evidently I\'m missing something because the WebView display

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 04:11

    James_D already explained in his answer how to convert "JavaFx CSS" to "HTML CSS", but it may be more convenient to use WebEngine.setUserStylesheetLocation to set a stylesheet that contains the CSS:

    webEngine.setUserStyleSheetLocation(getClass().getResource("style.css").toString());
    

    style.css contains the css code:

    body {
        background-color: #00ff80; 
        font-family: Arial, Helvetica, sans-serif;
    }
    

提交回复
热议问题