the first thing you have to to is to create a "style", that's to say you should first implement actions like changing cursor when mouse in on your component, urderlining the text, ...
the second thing is to create the hyperlink, and this problem is a little bit more difficult because you can do 2 things:
- maybe you just want to "contact" the server, typically you want to send data to a HTTP server via a PHP script so I need to execute script when clicking on the hyperlink
- maybe you want to open a browser and, or the path to browser is set somewhere and you can run a new process, or the path is not defined and I don't know how you can open the wanted URL.
There's a code used to join a server to execute a PHP script. This is nearly the same code if you want to show a html code in a HTML friendly component. To show HTML page, just use "retour" with by example jLabel1.setText(retour);
public boolean showHtmlPage()
{
boolean retour = true;
BufferedReader reader = null;
OutputStreamWriter writer = null;
String adresse = "http://my_site.com/my_page.php";
try
{
//encoding query parameters
String donnees = URLEncoder.encode("value1", "UTF-8")+"="+URLEncoder.encode(var1, "UTF-8");
donnees += "&"+URLEncoder.encode("value2", "UTF-8")+"=" + URLEncoder.encode(val2, "UTF-8");
//creating connection
URL url = new URL(adresse);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
//sending query
writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(donnees);
writer.flush();
retour &= true;
//reading query
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String ligne;
while ((ligne = reader.readLine()) != null) { /*System.out.println(ligne);*/ }
} catch (Exception e) { retour &= false; }
finally
{
try{ writer.close(); } catch(Exception e) { retour &= false; }
try{ reader.close(); } catch(Exception e) { retour &= false; }
}
return retour;
}
But I modified this piece of code from a source code I found on a Sun forum so I think you should find something like that if you continue searching on sun website and maybe it will suits you better.
The JComponents support html, so:
Email:
setText("<A HREF=mailto:address@domain.com>test email</A>>");
Web Page:
setText("<A HREF=http://www.google.com>test link</A>");
If it does not appear to be opening stuff, just use the Desktop class:
Desktop.getDesktop().browse(someURL);
Desktop.getDesktop().mail(someURI);