【发布时间】:2015-11-26 20:17:12
【问题描述】:
当一个 WebView 必须同时显示垂直和水平滚动条时,两个滚动条的交叉处会出现一个白色的小方块。
我想改变这个方块的颜色。
到目前为止我所尝试的
我首先尝试修改 WebView、Scene、JavaFX 滚动条的背景颜色。但显然:
WebView 不是您的 JavaFX UI 控件,而是显示网页的一部分。
(见this post)
所以根据this thread中找到的信息,我尝试修改以下元素的背景颜色:
- ::-webkit-scrollbar
- ::-webkit-scrollbar-track
- 身体
- html
- 甚至 div 看看我得到了什么
有人知道如何改变这个白色方块的颜色吗?
你可以在下面找到我使用的代码。
代码
Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("WebView.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
WebView.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.web.WebView?>
<AnchorPane
fx:controller="sample.Controller"
stylesheets="@WebView.css"
prefHeight="400.0"
prefWidth="600.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<WebView fx:id="webView" prefHeight="400.0" prefWidth="600.0"
AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0"/>
</children>
</AnchorPane>
Controller.java
package sample;
import javafx.fxml.FXML;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
public class Controller {
@FXML
public WebView webView;
@FXML
private void initialize(){
WebEngine engine = webView.getEngine();
engine.load("http://www.bing.com");
engine.setUserStyleSheetLocation(getClass().getClassLoader().getResource("sample/UserStyleSheet.css").toExternalForm());
}
}
【问题讨论】:
标签: java webview javafx scrollbar