Displaying a JLabel as an URL
Hi all,
i want to display a text on a JLabel and when the user move the mouse on it He/she has to understand that it is a link....as on an HTML page.
How can i do that ?
I found some example about it but they suggest me to assign an url to the JLabel text.
Any idea ?
Cheers.
Stefano
[326 byte] By [
warxsga] at [2007-11-27 8:31:17]

# 1
hi,
I wrote a class which extended JLabel Class and impelements the interface MouseListener.
Here there is the code of the class :
public class AttachUrlLabel extends JLabel implements MouseListener {
private String originalText;
private final String htmlText = "<html><u>?</u></html>";
public AttachUrlLabel(String text) {
super(text);
this.originalText = text;
addMouseListener(this);
}
public void mouseEntered(MouseEvent e) {
setText(htmlText.replace("?",originalText));
}
public void mouseExited(MouseEvent e) {
setText(originalText);
}
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
}
Enjoy.
Stefano