Open Browser when JButton clicked
Is it possible to open up a IE or firefox etc. browsers which will list all the files in the specified URL when a JButton is clicked.
Is it possible to open up a IE or firefox etc. browsers which will list all the files in the specified URL when a JButton is clicked.
absolutely
You can either use the Runtime class to run IE externally, or you can use the JDIC WebBrowser component to embed it in your app
can you give me a sample code or a webpage containing the information. i tried but unable to find it
Thanks
Runtime example: Put this code in your actionPerformed (or what ever you are using). This will not be platform independent since there are people who doesn't have IExplorer and also there are people having IExplorer in another directory than in this example. so this is not very good.
try{
// Execute a command
//OBS: you have to get the command right , you have to know were the browser is located
String command = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";
Process child = Runtime.getRuntime().exec(command);
}
catch(Exception exc){
System.out.println("Problem executing command. " +exc);
}
Other solotions
Have a look at this link: http://www.croftsoft.com/library/tutorials/browser/
(It is telling you that this problem is solved very easy with an Applet and that if you have not an Applet you can use the Non-Core API JNLP)
> Runtime example: Put this code in your actionPerformed (or what ever you are using). This will not be platform independent since there are people who doesn't have IExplorer and also there are people having IExplorer in another directory than in this example. so this is not very good.
As I always, say, for people looking for such features, it is always best in this case to switch to JDK 6.0 for a much simpler and more cross platform approach than using the the runtime exec method.
In JDK 6.0 you, have the java.awt.Desktop class which can be used to launch the default system browser when given a URL. Hence you do not have to know the location of the browser exe to launch it.
try {
URI url = new URI("http://www.google.com");
Desktop.getDesktop().browse(url);
} catch(Exception e) {
e.printStackTrace();
}
ICE
Isnt there any Funda of accessing defaut Browser,.
I mean i want to keep my application OS independent.
Please give me a better option.
Thanks. Also how do i access a directory from a remote server. .i want this directory show up as a list in the default web browser. ftp is not supported.
never mind. got the solution
icewalker2g :
> As I always, say, for people looking for such
> features, it is always best in this case to switch to
> JDK 6.0 for a much simpler and more cross platform
> approach than using the the runtime exec method.
Ah, sorry - I need to update my knowledge. I say thanks too.
> Ah, sorry - I need to update my knowledge. I say thanks too.
Always glad to be of assistance
ICE