Question

I have a JMenuItem which contains for example the label "mySite.com".

I added to it a listener to him like that :

 ...addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            /* do something */
        }
    });

So now I want to when I click to it, it redirect me to the http:/ /mySite.com.

Someone can enlighten me?

Was it helpful?

Solution 2

Use Desktop.browse(URI), which..

Launches the default browser to display a URI. If the default browser is not able to handle the specified URI, the application registered for handling URIs of the specified type is invoked. The application is determined from the protocol and path of the URI, as defined by the URI class.

OTHER TIPS

Read the section from the Swing tutorial on How to Integrate With the Desktop Class for working examples. The examples use buttons but the basic ActionListener code would be the same. You would want to use the "Browse" feature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top