Select to view content in your preferred language

Java ArcMap-Addin: Show html page with JEditorPane

464
1
05-19-2010 01:13 PM
TomSchuller
Frequent Contributor
Hy,
I'm working on a Java Tool-addin.

The tools should show up an html page.
I tried out with the JEditorPane.

The JEditorPane is working fine while running as single Java application. When the same code is integrated in a Tool-Addin to be executed in ArcMAP, I'm getting an exception.

Is there a way to use the JEditorPane in ArcMAP or an other possibility to display a html page in ArcMAP?

You find my JEditorPane code and the exception below.

Thanks,
Tom
 
JEditorPane editorPane = new JEditorPane("http://www.google.com");
editorPane.setEditable(false);
JScrollPane scollPane = new JScrollPane(editorPane);
JOptionPane.showMessageDialog(null,scollPane);



java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at javax.swing.JEditorPane.getStream(JEditorPane.java:810)
        at javax.swing.JEditorPane.getStream(JEditorPane.java:792)
        at javax.swing.JEditorPane.setPage(JEditorPane.java:419)
        at javax.swing.JEditorPane.setPage(JEditorPane.java:923)
        at javax.swing.JEditorPane.<init>(JEditorPane.java:259)
        at lu.etat.pch.gis.desktop.addins.HtmlRelatesPopup.mousePressed(HtmlRela
tesPopup.java:113)
        at com.esri.arcgis.addinframework.InternalTool.mousePressed(Unknown Sour
ce)
        at com.esri.arcgis.addinframework.InternalTool.onMouseDown(Unknown Sourc
e)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
Caused by: java.lang.reflect.InvocationTargetException
        at java.awt.EventQueue.invokeAndWait(EventQueue.java:997)
        at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1323)
        at javax.swing.JEditorPane.getStream(JEditorPane.java:802)
        ... 11 more
Caused by: java.lang.NullPointerException
        at java.util.Hashtable.put(Hashtable.java:394)
        at javax.swing.JEditorPane.registerEditorKitForContentType(JEditorPane.j
ava:1329)
        at javax.swing.JEditorPane.registerEditorKitForContentType(JEditorPane.j
ava:1311)
        at javax.swing.JEditorPane.loadDefaultKitsIfNecessary(JEditorPane.java:1
389)
        at javax.swing.JEditorPane.getKitTypeRegistry(JEditorPane.java:1346)
        at javax.swing.JEditorPane.createEditorKitForContentType(JEditorPane.jav
a:1271)
        at javax.swing.JEditorPane.getEditorKitForContentType(JEditorPane.java:1
128)
        at javax.swing.JEditorPane.setContentType(JEditorPane.java:1019)
        at javax.swing.JEditorPane.handleConnectionProperties(JEditorPane.java:8
25)
        at javax.swing.JEditorPane.access$300(JEditorPane.java:174)
        at javax.swing.JEditorPane$3.run(JEditorPane.java:804)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

0 Kudos
1 Reply
sankarsinha1
Deactivated User
Tom,

Can you please try the below code in the mousePressed method of the tool and see if it is working.

// Called when a mouse tool is pressed while the tool is active
@Override
public void mousePressed(MouseEvent me) {
     Runnable openEditorPane = new Runnable() {
         public void run() {
         Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
         JEditorPane editorPane = null;       
      try {
       editorPane = new JEditorPane("http://www.google.com");
      } catch (IOException e) {
       e.printStackTrace();
      }
      editorPane.setEditable(false);
      JScrollPane scollPane = new JScrollPane(editorPane);
      JOptionPane.showMessageDialog(null,scollPane);       
       }
     };
    SwingUtilities.invokeLater(openEditorPane);
}

-Sankar
0 Kudos