【问题标题】:Using WebView in JavaFX breaks the UI on Linux在 JavaFX 中使用 WebView 会破坏 Linux 上的 UI
【发布时间】:2016-06-15 08:11:25
【问题描述】:

我想在舞台上有一个 webview 组件和一个按钮,但是当我在 WebView 中加载 http://mail.google.com 时,舞台上绘制的另一个按钮会出现问题。

成功加载页面后,如果我将鼠标悬停在按钮上,按钮本身就会消失,只留下其标签可见。

问题仅出现在 Linux 上,因为当我在 Windows 上尝试相同的项目时,一切正常。

有趣的故事是,如果我更改要加载的网址,例如http://www.google.com,按钮不会受到这个奇怪问题的影响。

我的 Linux 64 位 Mint 17.3 和 Java 版本是 jdk1.8.0_91。 这是代码、video 和一些奇怪行为的屏幕截图。

package javafxwebviewnofxml;


import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;

import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;


/**
 *   
 * @author Aldo Marx    
 */
public class JavaFXWebviewNoFXML extends Application {

    public WebEngine webEngine;
    public  String urlToGo;
    public  AnchorPane anchorPane;
    private WebView webView;


    @Override
    public void start(Stage primaryStage) {

            Button btn = new Button();
            btn.setText("Say 'Hello World'");
            btn.setOnAction(new EventHandler<ActionEvent>() {

                @Override
            public void handle(ActionEvent event) {
                    System.out.println("Hello World my friends!");
                }
            });

            anchorPane = new AnchorPane() ;
            anchorPane.setPrefSize(1160, 900);  

            AnchorPane.setLeftAnchor(btn, 900.00);
            AnchorPane.setTopAnchor(btn, 400.00);

            webView = new WebView();
            webView.setPrefSize(1160, 900);
            webEngine = webView.getEngine();
             urlToGo =   "http://mail.google.com";   // this url is not okay 
         //   urlToGo =  " http://facebook.com";      // this url is okay 
         //  urlToGo = "http://www.google.com";   // this url is okay
            webEngine.load(urlToGo); 

            anchorPane.getChildren().addAll(webView);
            anchorPane.getChildren().addAll(btn);

            Scene scene = new Scene(anchorPane, 1160, 900);

            primaryStage.setScene(scene);
            primaryStage.show();
    }




   public static void main(String[] args) {
        launch(args);
    }

}

当它没有被鼠标悬停时出现在舞台上的按钮可以在下面看到

鼠标悬停在舞台上时出现的按钮(这就是问题所在)可以在下面看到

【问题讨论】:

  • 我建议您更改您的客户端密码。在互联网上发布机密通常不是一个好主意。
  • 好的,我会一起从项目中删除花哨的 URL。我对 mail.google.com 也有同样的问题,所以我不需要像这样复杂的 url 来显示这个问题。谢谢jewelsea!

标签: java linux javafx webview


【解决方案1】:

我通过将 -Dprism.order=j2d 添加到 VM 选项来解决此问题。

【讨论】:

    【解决方案2】:

    Don's set layout x, ... 当放置在 AnchorPane 中时,使用锚定:AnchorPane.setLeftAnchor 和类似

    【讨论】:

    • 完成,感谢米兰,但不幸的是,这并不能解决我的问题。
    猜你喜欢
    • 2011-11-01
    • 1970-01-01
    • 2020-02-10
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 2015-03-19
    • 2018-01-04
    • 1970-01-01
    相关资源
    最近更新 更多