2011-03-07 58 views
0

我在Java jframe中显示Google日历时遇到问题。在Java中显示Google日历JFrame

编辑:我看到谷歌日历,但它有一个蓝色的背景,它使得很难查看事件。

这里是我的代码

temp是谷歌的用户名一snipit。

private void getGoogleCalendar(){ 
    googlepane=new JPanel(new BorderLayout()); 

    String s="https://www.google.com/calendar/b/0/[email protected]&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; 
} 

回答

0

JEditorPane无法完整显示网页,因为它只支持HTML文本。 Google日历页面包含“JavaScript”。因此,在Web浏览器和使用JEditorPane的情况下,它会变成不同的显示方式。

我推荐使用Native Swing library (The DJ Project)。在sample page

  • 参考“JavaScript执行”。


“JavascriptExecution.java” 样品被用来确认运动。

原始

webBrowser.setHTMLContent(htmlContent); 

更改以下

final String urlString = 
    "https://www.google.com/calendar/" 
    + "b/0/[email protected]om" 
    + "&ctz=America/New_York&gsessionid=OK"; 

webBrowser.navigate(urlString); 

而且你有以下三个jar文件添加到车厢通票。

  • DJNativeSwing.jar
  • DJNativeSwing-SWT.JAR
  • SWT-3.7M5-Win32的Win32的x86.jar

这SWT库是在[目录该前进库] /库。或者,你可以得到(the Website

+0

谷歌没有提供一个HTML唯一的版本: https://www.google.com/calendar/b/0/[email protected]om&ctz=America/New_York&gsessionid =确定 但它仍然无法正确显示。我不断收到错误导致:java.lang.ClassNotFoundException:org.eclipse.swt.SWT当我尝试使用Dj项目 – 2011-03-08 03:46:15

+0

对不起,我误解了它。我添加了DJ Project的描述。 – 2011-03-08 05:44:59

+0

我宁愿没有一个特定于操作系统的jar,JEditorPane不显示html页面,但它具有蓝色背景,而不是白色。 – 2011-03-08 06:06:53