By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,778 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,778 IT Pros & Developers. It's quick & easy.

hyperlinks on a JFrame?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.