0

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;
}
Nazik
  • 8,696
  • 27
  • 77
  • 123
Steven Feldman
  • 833
  • 1
  • 15
  • 28

1 Answers1

0

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


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

Yu Sun corn
  • 616
  • 6
  • 8
  • Google does offer an html only version: https://www.google.com/calendar/b/0/htmlembed?src=0ap0d38a4vobr8i81805dla3hk@group.calendar.google.com&ctz=America/New_York&gsessionid=OK But it doesn't display correctly still. I keep getting error Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.SWT when I try to use the Dj Project – Steven Feldman Mar 08 '11 at 03:46
  • Sorry, I was misunderstanding it. I added the description of DJ Project. – Yu Sun corn Mar 08 '11 at 05:44
  • I would rather not have a os specific jar, JEditorPane does display the html page, but it has a blue background, instead of white. – Steven Feldman Mar 08 '11 at 06:06
  • It is a little pain that GUI does not depend on OS. It seems that the problem of JEditorPane is Stylesheet is not applied. – Yu Sun corn Mar 08 '11 at 07:25
  • I tried applying the style sheet, but no changes. I updated the code I am working with, can you tell me if I did it correct? – Steven Feldman Mar 08 '11 at 16:20
  • The HTML file of the calendar is compliant with HTML 4.01. However, JEditorPane corresponds only to HTML 3.2. (For example, the "class" attribute of CSS cannot be interpreted at HTML 3.2. )The solution with JEditorPane might be difficult though it is regrettable. I have no idea anymore. – Yu Sun corn Mar 10 '11 at 09:26
  • Thanks for the response, I noticed that there is an ical and xml link, is there a good calendar gui that would work better? – Steven Feldman Mar 10 '11 at 20:17
  • I don't know iCal. And I recommend you post it as new question. – Yu Sun corn Mar 11 '11 at 01:38