【问题标题】:JavaFX Scrollbar intersection's color in WebViewWebView中JavaFX Scrollbar交叉点的颜色
【发布时间】: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


    【解决方案1】:

    现在已经快一年了,但是对于任何需要知道如何实现这一目标的人来说,都可以用这个来完成

    .corner {
        -fx-background-color: transparent;
    }
    

    您还可以使用此链接了解有关样式化滚动条的更多详细信息:http://www.guigarage.com/2015/11/styling-a-javafx-scrollbar/

    【讨论】:

      猜你喜欢
      • 2013-03-08
      • 1970-01-01
      • 2013-12-16
      • 2022-01-05
      • 1970-01-01
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多