Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Open a JavaScript in Google Chrome on a Mac computer

794044Sep 15 2010 — edited Sep 16 2010
My question is simple:
How can I open a JavaScript file with Google Chrome on a Mac computer using Java?

This is my code so far:
JOptionPane.showMessageDialog(null, "Please browse to Google Chrome!");
                            JFileChooser fc = new JFileChooser();
                            FileFilter ff = new FileFilter() {

                                public boolean accept(File pathname) {
                                    if (pathname.isDirectory()) {
                                        return true;
                                    }
                                    if (pathname.getName().toLowerCase().equals("chrome.exe") || pathname.getName().toLowerCase().equals("chrome.app")) {
                                        return true;
                                    }
                                    return false;
                                }

                                @Override
                                public String getDescription() {
                                    return "chrome.exe; chrome.app";
                                }
                            };
                            fc.setFileFilter(ff);
                            int returnVal = fc.showOpenDialog(null);
                            if (returnVal == JFileChooser.APPROVE_OPTION) {
                                try {
                                    Runtime.getRuntime().exec("open " + fc.getSelectedFile().toURI() + " " + f.toURI());
                                } catch (Exception exxxx) {
                                    JOptionPane.showMessageDialog(null, "Unknown exception occurred! It's: " + exxxx.toString() + "\n" + "fc.getSelectedFile().toURI()");
                                }
                            }
I have little to no Mac knowledge, but this code opens Google Chrome, Safari and Finder at once...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 14 2010
Added on Sep 15 2010
13 comments
388 views