0

In my java application, I have a list of links which I would like to open in default browser:

Link List

How to open it is pretty much clear based on this answer Open a link in browser with java button?.

What I'm trying to find out now is, how do I know which one of the links I'm triggering since they are all together in a file.

Does anyone has a good suggestion to this? because until now the only thing I could thought was create a JButton to each link and detect it through a listener but this seems not to be the most efficient solution. The links needs to be opened individually and If its possible I would like to trigger directly through the link.

Community
  • 1
  • 1
Victor Oliveira
  • 3,293
  • 7
  • 47
  • 77

1 Answers1

0

I found out my own answer. Java provides an interface named HyperlinkListener. With HyperlinkListener you can detect which link is being triggered.

In code lines this means:

    @Override
public void hyperlinkUpdate(HyperlinkEvent arg0) {

        if(arg0.getEventType().toString() == "ACTIVATED")
            System.out.println(arg0.getURL());  
            //openWebpage(arg0.getURL());

}

This simple code will output the link you want to trigger, and to open in the default browser you just need to merge my answer with the answer of this post.

Community
  • 1
  • 1
Victor Oliveira
  • 3,293
  • 7
  • 47
  • 77