我想在舞台上有一个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);
}
}
答案 0 :(得分:1)
我通过将-Dprism.order = j2d添加到VM选项来解决了这个问题。
答案 1 :(得分:0)
Don设置布局x,...放置在AnchorPane中时,使用锚点:AnchorPane.setLeftAnchor和类似的