• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help c JList & File opening

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have several a JLists from which I've listed files on my drive. I wish to be able to open/run the files(eg word documents/excel/pdf) when the file of choice is double clicked. I want the file to be opened to be based on the JList choice. Please help!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, this doesnt seem to have anything to do with Servlets, the forum you posted in, so I'm moving it to Swing where people may be able to help...
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, basically, when you click on the item, you need to find the extension of the file, then use some SWITCH CASE or IF statement to determine which program to use. Then you will need to use Runtime.exec(args) to run the appropriate application. Most applications like Word and Excel will allow you to run a file and open the document like:
"excel.exe filename.xls"
That is the only way I can think of. Since application and file extension mapping is very OS specific, I can't see something like this being inherent in the JAVA API anywhere.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On windows, with some files you can pass them to the cmd.exe (or whatever is appropriate for your windows version) and it will launch the file in the associated application.

Also, if you're not tied to Swing, I seem to remember SWT does provide some kind of "launch this file in the associated program" code that at some level touches the OS (if you don't define an association yourself)... if you're interested look at the org.eclipse.swt.program.Program class.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, if you're not tied to Swing, I seem to remember SWT does provide some kind of "launch this file in the associated program" code that at some level touches the OS (if you don't define an association yourself)... if you're interested look at the org.eclipse.swt.program.Program class.
Ahh, I forgot about that. SWT also offers some ActiveX libraries and lets you actually embed certain Windows Apps like Excel and Word inside of an SWT Frame/Application. Might serve your purpose a bit.
 
reply
    Bookmark Topic Watch Topic
  • New Topic