470,833 Members | 1,327 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

hyperlinks on a JFrame?

Hello!

I'd like to ask a question about if it is possible to open a browser
from a java program.

I'm working with JBuilder X foundation. I have a frame or dialog
- about box - and I would like to place a link to a website with
help.

Either I would like to do it from the program, by a button, and
to run the browser somwhere in the program body, or I'd like
a label to be a link, like in some programs. This should need
no code, just the right URL.

Is it possible at all?

TG.

Jul 17 '05 #1
1 3243
Yes it is possible.

Use a JLabel or a JButton with an action listener such that when it is
clicked a URL is opened. You can use a JEditorPane and call its
setPage method.

e.g. something like this might work:

JButton b = new JButton("Click here for help") ;
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
myEditorPane.setPage("http://www.myurl.com/help.html") ;
}
}) ;

If you want to open an external browser such as netscape, you could
use
Runtime.getRuntime().exec("netscape http://www.myurl.com/help.html") ;
or some variant of the above.

--
Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking..."
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

Shinzon
5 posts views Thread by Shinzon | last post: by
Shinzon
5 posts views Thread by Shinzon | last post: by
3 posts views Thread by coffeetime | last post: by
3 posts views Thread by coffeetime | last post: by
2 posts views Thread by zahit | last post: by
6 posts views Thread by gaya3 | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.