Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling programs

Status
Not open for further replies.

fatcodeguy

Programmer
Feb 25, 2002
281
CA
Hi, I have a program that generates reports in an html format, and if the user wants to view the report, he clicks a button, and it loads the report file in the default web browser. Any suggestions on how to do this?

thanks
 
Which part are you having trouble with? The whole thing?

If you want to see how to launch a browser from java, search the archives. I've answered this before. For the rest, you'll have to give us an idea of what you don't know how to do.
 
Hi, I think I got it (though couldn't find it in archive forums, but in Java FAQ).

Runtime.getRuntime().exec("start c:\path\to\file ");

This will only work on Win unless a specialized start script is written for any other platform. Is this the method you would suggest?

Thanks

 
Well, in general, any time you want to call a native program you are tying yourself to the platform you are writing your code for. This is why I don't recommend this approach if you are attempting to make your code portable.
 
You can use a JEditorPane or a JTextPane to display
html pages. (like a browser) If there is any embedded
script or anything like that you need to use the browser
but for simple formatted html reports they're fine.
This way it displays as part of your app.
 
This is a good solution if you don't mind if the HTML in the pane is 'inactive'. While the pane will correctly display hyperlinks, etc., clicking them won't do anything.
 
Actually you can enable the hyper links by providing
a listener. The editor pane has to be set to
pane.setEditable(false) in order for it to generate
events. Then make your app implement the
HyperLinkListener interface and provide a hyperLinkUpdate
method.

public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
JEditorPane pane = (JEditorPane) e.getSource();
try {
pane.setPage(e.getURL());
} catch (Throwable t) {
t.printStackTrace();
}
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top