954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

unable to open url through JLabel link in Windows 7

Hi,

I am trying to open a url by clicking over the link of JLabel in Windows 7 (32 -bit) but unable to do so. After clicking on the link, it doesn't do anything. Although, it is opening the file successfully.It used to work in XP.

The code is as follows:


String osname = System.getProperties().getProperty("os.name").toUpperCase();
if (osname.startsWith("WINDOWS")){
Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL \"" + path + "\"");
}
else{
String[] commands = {"start", "\"\"", path};
Runtime.getRuntime().exec(commands);
}

I would appreciate your help.

neil.abbott1
Newbie Poster
2 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

See if the browse() method of the Desktop class works for you.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

String[] cmd = new String[5];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = "start";
cmd[3] = "\"\"";
cmd[4] = path;

try {
Runtime.getRuntime().exec(cmd);
}
catch (IOException e) {
}

The above code worked. Thanks anyway!

neil.abbott1
Newbie Poster
2 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You