【发布时间】: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!