在Java JFrame中显示Google日历
我在java jframe中显示谷歌日历时遇到问题。
编辑:我确实看到谷歌日历,但它有蓝色背景,这使得查看事件变得困难。
这是我的代码片段
temp
是谷歌用户名。
private void getGoogleCalendar(){ googlepane=new JPanel(new BorderLayout()); String s="https://www.google.com/calendar/b/0/htmlembed?src=groupboba@gmail.com&ctz=America/New_York&gsessionid=OK"; JEditorPane tp=new JEditorPane(); try { HTMLEditorKit kit = new HTMLEditorKit(); StyleSheet styles =kit.getStyleSheet(); styles.importStyleSheet(new URL(s)); kit.setStyleSheet(styles); kit.install(tp); tp.setContentType("text/html"); tp.setEditorKit(kit); tp.addHyperlinkListener(this); tp.setEditable(false); tp.setPage(s); tp.setBackground(Color.white); } catch (IOException e) { e.printStackTrace(); } googlepane.add(tp, BorderLayout.CENTER); return; }
JEditorPane无法完全显示网页,因为它仅支持html文本。 Google日历页面包含“JavaScript”。 因此,对于Web浏览器和使用JEditorPane的情况,它会变成不同的显示。
我建议使用Native Swing库(DJ Project) 。
- 请参阅示例页面上的“Javascript Execution:” 。
“JavascriptExecution.java”示例用于确认移动。
原版的
webBrowser.setHTMLContent(htmlContent);
改变以下
final String urlString = "https://www.google.com/calendar/" + "b/0/htmlembed?src=0ap0d38a4vobr8i81805dla3hk@group.calendar.google.com" + "&ctz=America/New_York&gsessionid=OK"; webBrowser.navigate(urlString);
并且您必须将以下三个jar文件添加到类传递中。
- DJNativeSwing.jar
- DJNativeSwing-SWT.JAR
- SWT-3.7M5-Win32的Win32的x86.jar
这个swt库位于[进展库的目录] / lib中。 或者你可以得到( 网站 )