• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding icons  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. I am designing an application that will allow users to attach files to a document. I have gotten as far as allowing them to browse via the JFileChooser..... then I got stuck. Once they choose the file they want to attach, I want to display that file on the JPanel with the corresponding icon for the file type..... so if they pick a .pdf it will display the .pdf icon (if they have Adobe Reader), if they choose an excel file, it will display the excel icon, etc. And of course when they double click on the icon (or button) it will pull the default program associated with that file type. How can I accomplish this?
Thanks for any help!
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two questions there. For the first, go through the API of javax.swing.filechooser.FileSystemView and for the second, java.awt.Desktop.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay.... I went through the API's and think I found what I was looking for...... Originally I was thinking I was just going to store the UNC path to the attachments.... but then realized that maybe I actually need to store the attachment itself in a database. I've never really worked with this type of thing before....
1st question..... how do I store the actual attachment in the database. What data type would I use (I'm using DB2)?
2nd question.....once those attachments were stored in the database, what API would I use to open them with? Can I still use the Desktop API?

Thanks for any help!
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) BLOB is mostly used for binary contents.

2) You'll have to extract them to a physical file. File has two static methods for creating temporary files. Combined with deleteOnExit() you could have those files exist only until your application ends. (deleteOnExit will fail silently if the file is still in use at that time though.)
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay.... so I see how to retrieve the file... how do I store the file in the database as a BLOB? When the user click on the "attachments" JButton.... it opens up a JFileChooser for them to navigate to the attachment......I would assume I would have to do something as far as saving the path. How do I convert that file path into a BLOB object to save to the database?
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSet and PreparedStatement have methods that deal with binary input. Check those out.
If you don't know how to copy data from an InputStream to an OutputStream check out the code at the bottom of this page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!