• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to make a simple hyperlink in a swing frame

 
ali rafiq
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to make a simple hyperlike like i make this class now whats i have to do for the event

import javax.swing.*;
import java.awt.*;
public class Lab extends JFrame
{
Lab() {
JPanel a = new JPanel();
Container con = getContentPane();
con.setLayout(new FlowLayout());

JLabel label = new JLabel("<html><table><tr><td>hi</td><td>helloo</td> </tr><tr><td>hi</td></tr></table>The <em><a href=e:/j.html >list</a></em> word is <b>bold</b>");
con.add(label);

setVisible(true);
setSize(200,200);
}
public static void main(String arsg[])
{
new Lab();
}
}
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
What do you want to do?
EITHER you want to trigger an event that is dispatched through a MouseClick:
Attach a MouseListener to the JLabel and do whatever you want in its implementation. Though you should think about using JButton as the user will most likely click rather on a Button than on a Label.
OR you want to display an HTML page:
For displaying HTML you need the JEditorPane. See the Swing Tutorial about it. It's very well documented. There are special event listeners for HTML links.
For triggering the display of a HTML page: The user might click on a button, and then a JEditorPane is opened that loads the URL that is specified in (or generated by) the implementation.
cheers
Chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!