简体   繁体   中英

Displaying Google Calendar in Java JFrame

I am having trouble displaying a google calendar in a java jframe.

Edited: I do see the google calendar, but it is has a blue background and it makes it difficult to view events.

Here is a snipit of my code

temp is the google username.

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 can not display completely the Web page because it supports html text only. Google Calendar page includes "JavaScript". So it becomes a different display in the case of a web browser and the case of using JEditorPane.

I recommend to use Native Swing library (The DJ Project) .

  • Refer to "Javascript Execution:" on the sample page .


"JavascriptExecution.java" sample is used to confirm movement.

Original

webBrowser.setHTMLContent(htmlContent);

Change following

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);

And you have to add the following three jar files to the class pass.

  • DJNativeSwing.jar
  • DJNativeSwing-SWT.jar
  • swt-3.7M5-win32-win32-x86.jar

This swt library is in [Directory that progresses library]/lib. Or you can get ( the Website )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM