Possible Duplicate:
How to add hyperlink in JLabel
In my program, I am searching through an index using Lucene and I am retrieving files. I have created XML files for the retrieved docs from the Lucene's search. Now, I want to make these XML files as hyperlinks and display to the user as the search results. That is I want the XML files to be open when the user clicks on this hyperlink. Any help appreciated!?
for(int i=0;i<file_count;i++)
{
file=str+index[i]+".xml";
JLabel label = new JLabel(file,JLabel.CENTER );
label.setOpaque(true);
label.setBackground(Color.RED);
panel.add(label) ;
label.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
if(evt.getClickCount() > 0)
{
Runtime r= Runtime.getRuntime();
try {
System.out.println("testing : Inside mouseclicked");
Process p = r.exec("cmd.exe /c start "+file);
System.out.println("opened the file");
} catch (IOException ex) {
System.out.println(ex.getMessage());
System.out.println();
}
}
}
});
}
Here is the code that I have made. In this, I am suppose to get output on the screen "file_count" no of times. I am getting that but what is happening is all the links are showing the same file when clicked. Help?