本人是在应用程序中加入百度地图网页版本html文件;
- java swing插入网页过程
加入JFXPanel和WebView,代码如下所示;
WebView webView = null;
JFXPanel jfxPanel =new JFXPanel();
public void adbBaiduGpsCenterContent() {
// jPanelBaiduGpsDo.setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.gray, 0, false), "gps"));
jPanelBaiduGpsDo.setPreferredSize(new Dimension(450, 400));
Platform.runLater(new Runnable() {
@Override
public void run() {
webView = new WebView();
jfxPanel.setScene(new Scene(webView));
WebEngine webEngine = webView.getEngine();
webEngine.load(ClassLoader.getSystemClassLoader().getResource("html/map.html").toExternalForm());
}
}
);
jfxPanel.setPreferredSize(new Dimension(400,400));
jPanelBaiduGpsDo.add(jfxPanel);
jPanelBaiduGpsDo.setLayout(new FlowLayout(FlowLayout.LEFT, 20, 10));//new GridLayout(4,4,20,30)
}
- 遇到问题JFXPanel第一次显示,后面不显示查阅文章JavaFx JFXPanel无法刷新,只能第一次显示的问题_softfuncsdn的博客-CSDN博客和JavaFX-5(Platform类的使用)_platform.setimplicitexit(false)_longjingyu1992的博客-CSDN博客解决办法是在main后面加入
Platform.setImplicitExit(false);//设为false,则窗口关闭后程序不会退出;除非调用了Platform.exit();
public static void main(String[] args) throws IOException, ScriptException, NoSuchMethodException {
设为false,则窗口关闭后程序不会退出;除非调用了Platform.exit();
Platform.setImplicitExit(false);
- 个人程序截图