Best way to manage images in a swing app

Hi.
I have a swing app that uses alot of images around 100+ at around 40kb each.
I am currently using new ImageIcon("icon\\main.png")) to create them.
Is this the most efficient way to manage images?
Would it be more efficeint to store then in the mysql database?
and / or use SwingWorker (http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html)
Cheers
Bobby

Hi Bobby,
It depends on what you want to be more efficient:
1) CPU cycles
2) Reducing jar size
3) Ease of maintenance
4) Prevent typing errors in file names
For me, number 3 and 4 are important. So, what I generally do, is create an enum that desribes the images that are contained in the same package as the enum. Now I'm able to change the package name with no consequence. I only have to type the filename once and know when I have to double check of what I type. Something like this:
package org.pbjar.geom.images;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public enum Images {
    AUTHOR_SMALL("TheAuthor.jpg"),
    AUTHOR_LARGE("PietKopLarge.jpg"),
    private final String filename;
    Images(String filename) {
     this.filename = filename;
    public ImageIcon getIcon() {
     return new ImageIcon(getImage());
    public BufferedImage getImage(){
     try {
         return ImageIO.read(getURL());
     } catch (IOException e) {
         throw new RuntimeException(e);
    public URL getURL() {
     return this.getClass().getResource(filename);
}Piet

Similar Messages

  • Best way to manage images on jsp web application

    Hi,
    Am developing a jsp web application, in that project, the user will upload the image files, now I created an image directory in the context root and when the image is uploaded by the user it is saved in the /images directory and the image path is saved in the database. I can display this image using the <img src="images/a.jsp" > tag.
    but when I rebuild the project all the images in the /images directory get deleated but the image path is remained in the database, is there any method that I make /image dir outside my project context root so that when I rebuild the project the /images dir can get changed and my project will save images outside the context root that is in the /images dir which is now outside the project context root. and is it possible to display those images using <img src""> tag. because this time my /images dir is at D:/images . what could be the best method or way to handle images with the web application.
    any suggestion will be helpfull

    Well my friend as per your given case there are to two ways of approaching your problem.
    Case 1:
    How to save the relevant data ??
    .Create a backup folder Workstation on which you are hosting your application where you can store all the uploaded files which is outside the scope of webserver(However we can write a dedicated servlet which can access that file) and make sure we pickup from any the folder path from a specfic MessageResource bundle or an context/servlet init parameter in web.xml.
    .Write a Upload servlet/Backing Bean which saves all the files in the discussed folder using utility packages like Commons FileUpload,Oreilly MultipartRequest & etc and then register saved fileName in the database user specfic table specific to user.
    How to display the Image ??
    .Write a dedicated servlet which can pickup user related fileName specfic information from the database and the read the file from backup folder by constructing the path from the entry made as a init param in web.xml or any other custom MessageResource bundle and then stream the Image data using the ServletOutputStream.
    NOTE: do not forget to pickup & setImage file ContentType & Set the content length.
    .Just try to render the JSP view file where we are displaying the displaying the images by calling the dedicated ImageServlet.
    <img src="ImageServlet?userid=2345" align="center"/>Try to refer below posts to get a better understading.
    Dedicated Image Servlet:
    http://forum.java.sun.com/thread.jspa?threadID=5208858&messageID=9840042#9840042
    Uploading Files Using Servlet:
    http://muimi.com/j/jakarta/commons/fileupload/
    Case 2
    The second method would more or less the same but here we would save the uploaded file
    content is saved in the Database as a Blob and we would retrive it back using a dedicated image servlet again.
    However,in terms of performance the second case implementation is very costly.
    Try to refer below posts to get a better understading on the second case.
    http://forum.java.sun.com/thread.jspa?threadID=5193481&tstart=50
    http://forum.java.sun.com/thread.jspa?threadID=5211649&messageID=9853670#9853670
    Hope this might help :)
    REGARDS,
    RaHuL

  • Whats the best way to manage 100s of thumbnails?

    I'm trying to build a simple photo management app in java, like Picasa2. I want to be able to scroll through 100s of thumbnails. Whats the best way to manage them from a memory standpoint?
    a) can I load up 100s of thumbnails into a JScrollPane? If so, will it do anything special to manage memory for the thumbnails that are offscreen?
    b) should I just draw up a grid of JLabels and page through them like you would in html?
    Is there another approach? Is there any special way to manage the thumbnails that are offscreen (besides loading them all in memory ) and still get a fast response time?
    BTW, if anyone wants to join me in this project, I'm happy to opensource and share.

    Because for some of us, it takes a lot longer than 5 mins. Besides, I was on someone else's computer.
    Regardless, I've implemented JList for images, and it works really well. For those of you who are following in my footsteps, the answer is:
    JList renders ImageIcons by default.
    If you want to render a JLabel with an ImageIcon set to an image, you need to write a custom ListCellRenderer, but it turns out that is not too hard. But here is a follow-up problem:
    My app has JLabels that subscribe to an ImageLoader that loads images in the background. On init() the JLabel just has the ImageIcon set to a placeholder image:
              myJLabel.imgIcon = new ImageIcon();
              myJLabel.imgIcon.setImage( myPlaceholderImage );
    However, once the actual image is loaded, I call a refresh method to set the ImageIcon to a new image:
              myJLabel.imgIcon.setImage( myLoadedBufferedImage );
    My problem is getting the JList to render the updated JLabel. Right now, I keep a reference to the JList with myJLabel and call revalidate() on refresh, but that doesn't seem very clean.
    Is there an easy/natural place to get the JList to revalidate()?
    Can I easily know which JLabels are in the viewport of the JList scrollpane? That way I could revalidate only the visible JLabels or when scrolling.

  • What is the best way to display image ??

    hi my questions is unusual, there are so many ways to display images.
    I m developing image processing s/w can any one suggest me which would be the best way to display image on which i can perform image operations.
    like in JPanel, icon, trhough paint() or anything else...
    thank you..In advance

    hi man... i think so imaging is better with JAI(Java Advanced Imaging) .... is perfect for display in jcomponent like JPanel or JLabel, you have to replace the paintComponent().
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.geom.AffineTransform;
    import javax.media.jai.PlanarImage;
    import javax.swing.JComponent;
    class ImagePanel extends JComponent {
         protected PlanarImage image1;
         protected AffineTransform atx= new AffineTransform();
         protected int width, heigth;
         public ImagePanel() {
         public ImagePanel(PlanarImage i) {
              image1= i;
              width= i.getWidth();
              heigth= i.getHeight();
         public void paintComponent(Graphics gc) {
              Graphics2D g= (Graphics2D)gc;
              Rectangle rect= this.getBounds();
              if ((width != rect.width) || (heigth != rect.height)) {
                   double magx= rect.width / (double)width;
                   double magy= rect.height / (double)heigth;
                   atx.setToScale(magx, magy);
              if (image1 != null)
                   g.drawRenderedImage(image1, atx);
    if you need more info, ask about JAI api and docs

  • What is the best way to manage multiple devices with one iMac - different users with seperate itunes accounts or one mac user with different itune logons and libraries?

    Hello
    I have just purchased an imac which I am very happy with.  In our household we also have two iphones (one mine and one husbands) and one ipod (my sons). We all have individual itunes accounts set up on our previous computer (not a mac). We have sepereate apps and music, although there may be the odd occasion where we would like to share a song (if this is possible) across devices.
    I am just wondering the best way to manage these devices using the new imac.  Should I create individual accounts to logon to the imac, then from within these launch our own itunes accounts and sync our devices with these.  Or should I be using one version of itunes, logging on to this with our different itunes usernames and storing things in libraries.
    Any help would be greatly appreciated. 
    Thanks

    I am presuming that we cannot share downloaded apps and music between accounts because of the copyright issue,
    Though I'm no copyright lawyer, as long as it's within a household, you can share content among users. Such sharing is, absent specific language preventing it not present in the iTunes Store terms of use, generally considered to be "personal use". So you can share apps and music amongst your users on your computer and with their devices. You just can't give any of that content to friends or relatives who don't live with you.
    What I am not clear on, it making sure that this appears in each itunes account - is it easy to find the file storage folders that match the itunes accounts and what would these be?
    The iTunes library and files are by default in a user's Home/Music folder. But you don't have to find the folder; in fact putting a file into the folder yourself won't add the file to iTunes. Just drag the file into the iTunes window. iTunes will copy it to the correct location.
    Regards.

  • What's the best way to manage Apple IDs for multiple devices?

    Hi,
    We have
    a shared Macbook air
    a shared iPad
    my iPhone
    his iPhone
    We want to put one ID on the Macbook and iPad that we can use to have the same iMessage on both and that we can put a card on and use in the iTunes store etc.
    We also want to have our own iMessages on our iPhones, plus be able to use the account with the cards on them to purchase and share across devices...
    What's the best way to manage them all?

    Welcome to the Apple Community.
    iTunes is straight forward, just use the same ID on all of them.
    What exactly do you want to see in messages on the Mac and iPad, messages combined from each of your phones or a different account just for both of you.
    You should think about what you want in calendars, contacts etc, on your shared devices.

  • Best way to manage multiple iTunes accounts (from different countries)

    Ok, wasn't sure if this was the best community to ask this question, but here goes.
    My wife and I have two iTunes accounts, one originally from the United States, the other originally from Australia. Over the years content has been purchased using both accounts.
    We currently reside in Australia and primarily view our content on Apple TV. So far we’ve had no problems logging into either account and accessing all our content.
    Now, I have a fear (perhaps an irrational one) that if we choose to permanently reside in one country (Australia, the US, somewhere else) that at some point Apple may cancel/restrict one of these accounts. Since there is no way for me to merge all our purchased digital content into the one digital library, we’re now wondering the best way to manage this?
    I see there is a new "family sharing" feature soon to be launched, so that may be half the solution (assuming it will work with family members in different continents). If so, the other half of the question is, will we be able to still purchase content on both accounts? While in Australia since April we have rented movies on both accounts, but have only purchased movies etc on the Australian account (we can still do this on the US account, but we haven't risked it in case it gets cancelled because Apple decides we're no longer in the US - in other words, we don't want to spend $$$ on movies we may not be able to access in future).
    What do others think? What is the best way for us to manage our scenario? Or am I worried about nothing and we can continue purchasing content on either account without fear of “losing” it later?
    Any advice would be greatly appreciated! I did try and ring Apple, but the guy refused to give me advice until I provided my details and I did't want to do that at this stage.
    Thanks everyone for your help!
    MM

    You may lose the ability to purchase content from the USA, but any content you've already bought will remain accessible. Back everything up.
    (112502)

  • How is the best way to manage the stats table?

    Hello!
    I have the Integration 2.1 working with an Oracle 8.1.7 db. I noticed that the table
    STATS is growing pretty fast.
    How is the best way to manage this table?... I haven't found something related with
    this issue in the documentation, but at least I want to know how to safely delete
    records from this table.
    For example, if I know the minimal time I have to keep in the table, is quite simple
    to create a shell script and/or Oracle pl/sql job to trim the table.
    I hope somebody can help me!!!!
    Thank you!
    Ulises Sandoval

    Write an app people want to buy and rate highly.

  • What is the best way to manage photos - Dropbox (with sync), Facebook (with sync), iPhoto, etc.?

    With so many cloud based and wireless syncing services, I'm lost as to the simplest way to keep photos sync'd as well as backed up. My dropbox is currently syncing all photos I take with my iphone, but in an overall folder called CAMERA UPLOADS, so they are uncategorized. I upload pics to facebook, which facebook also has a sync photos feature, but I don't necessarily want all photos uploaded to facebook. What has worked best for everyone so that there aren't a ton of dupicate photos everywhere, and multiple syncs of the same photos?
    Also, what is the best way to manage my iPhone photos generally? I'm never sure if I delete a photo from my phone, does it delete it on my computer via iCloud? Sometimes I just take a picture to send to a friend that I don't need to keep, while others are ones I want to sync to my computer. Can I control when deleting that it be deleted everywhere or just on the device? And alternately, can I choose certain photos not to sync via iCloud?
    iCloud makes me nervous. Once when I wanted to place all photos of my pup into a folder, I selected the photos on my iPhone and accidentally clicked delete instead of move. No big deal, I figured they'd be at home sync'd on the cloud. But since I'd deleted them on my phone, the cloud deleted them on my home computer too and the photos were lost.

    I am presuming that we cannot share downloaded apps and music between accounts because of the copyright issue,
    Though I'm no copyright lawyer, as long as it's within a household, you can share content among users. Such sharing is, absent specific language preventing it not present in the iTunes Store terms of use, generally considered to be "personal use". So you can share apps and music amongst your users on your computer and with their devices. You just can't give any of that content to friends or relatives who don't live with you.
    What I am not clear on, it making sure that this appears in each itunes account - is it easy to find the file storage folders that match the itunes accounts and what would these be?
    The iTunes library and files are by default in a user's Home/Music folder. But you don't have to find the folder; in fact putting a file into the folder yourself won't add the file to iTunes. Just drag the file into the iTunes window. iTunes will copy it to the correct location.
    Regards.

  • What is the best way to manage my iPhoto, which is taking up too much space on my MacBook Pro?

    What is the best way to manage my iPhoto, which is taking up too much space on my MacBook Pro?
    Specifically, I'd like to keep some of my favorite pictures on the laptop while moving the rest to an external hard drive. Is there a way to tag just a few pictures inside an event/album as "favorite", while storing the rest in an EHD, but still keep them connected to the same event/album? I'd like to have just the favorite pictures on the laptop, but when I have the EHD connected,  be able to view all my pictures in the same place, and not have to browse through separate hard drives. Ideally, whether or not a picture is designated as "favorite" will determine where it resides.
    Is this at all possible?
    I have only 7 GB left on my HD and I'm desperately needing a solution!
    Thanks!

    You need two libraries to do this. One on the external with all your Photos. One on the internal with a subset - your favourites. You do it this way to make backing up easier - that is, back up the library with everything, so you're only backing up one.
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    Now you have two full versions of the Library.
    3. On the Internal library, trash the Events/albums/photos you don't want there
    Now you have a full copy of the Library on the External and a smaller subset on the Internal
    Some Notes:
    As a general rule: when deleting photos do them in batches of about 100 at a time. iPhoto can baulk at trashing large numbers at one go.
    You can choose which Library to open: Hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Choose Library'
    You can keep the Library on the external updated with new imports using iPhoto Library Manager

  • Best way to manage iMac and two iPads?

    Have a new iMac (Intel,OS X Lion) and two iPad 2.  The iMac is mine the and iPads are my kids. We all have our own apple IDs.  I ultimately want to do any downloading/purchasing on the iMac and then transfer the music/apps/movies to the iPads.
    What is the best way to manage them so I can sync the iMac to the iPads? 
    Can I download apps/music etc. on my iMac and then sync it to both of the iPads?
    Do I need to use the same Apple ID on all of them if I want to sync the iMac to the iPads?   I would prefer not to store credit card info on the kids iPads.
    Whats the most efficient way to handle this?  Sorry for so many questions.  Its a hazard of being a newbie.
    Thanks, Courtney

    The best way I can think of is for each iMac user create their own account for them. Then when they log in they can sync to their own AppleID account. It keeps things simple and separate. If you don't know how to create accounts please look over http://docs.info.apple.com/article.html?path=Mac/10.7/en/mtusr001.html

  • Best way to manage large library with AAC and MP3 versions of files

    I have a large library of music. I listen to music through iTunes and iPod/iPhones, but also other devices which only support MP3, and not AAC. I typically convert iTunes purchases to MP3, but I'm left with two copies of each song in the same folder. I'm looking for recommendations on the best way to manage what would essentially be a duplicated music library - a high quality version I use with my iTunes/ipods, and a lower quality MP3 version for the devices that only support that format.

    I have had a similar problem. I have all my music residing on a NAS where I access it from iTunes (for managing my iPods/iPhones) and a Tivo PVR (which is connected to my house stereo system.) The problem is that Tivo does not recognize AAC. So I've used iTunes to create mp3 versions of all my purchased AAC music. Because the NAS is set as my iTunes media folder location, iTunes puts the mp3 copies back into the existing folder structure (which it keeps organised) on the NAS. Tivo accesses the NAS directly, over the network. But iTunes also puts the additional copy into the iTunes library which leaves me with multiple copies of the same songs on iTunes AND my iPods. Having multiple copies on the NAS (mp3 for Tivo and AAC for iPod) is OK: I've got plenty of space on the NAS and the Tivo doesn't 'see' the AAC files.
    The solution I'm planning to implement is to delete the mp3 entries from the library as soon as I create them (leaving the files in the media folder.) But what I'm looking is for a way to automatically select the mp3 copies (for deletion) from the existing duplicates list. Any ideas?

  • Best way to manage small pieces of a 13 minute clip?

    A client has given me some AVI footage to cut in with some of my material.
    He's said 'at 13 min, 40 seconds' use 5 seconds. 'at 12 min, 10 seconds, use 8 seconds'.
    There will be some fades and I'll be adding text, etc. in Motion.
    What's the best way to manage this?
    I'd guess cutting this long clip info small pieces out using FCP and then import them into Motion?
    But, I was curious if there was a way to work completely in Motion?
    Also - if I drag from the edge of a clip in motion, thus changing the part of the clip displayed, I can't really tell what the timecode is (of the original position) even when I've turned on timecode rather than frames. Which would make doing any edits by absolute timecode rather hard.
    Is there a way to see the absolute timecode position in the clip after changing the parts of the clip that are displayed?

    Your original idea is right on. Cut up the clip in FCP. Don't try to work with a 13-minute clip in Motion - it won't like you. Motion will probably constantly crash try to process something that big, and it will just cause headaches.
    FCP will also display the absolute timecode.

  • Best way to manage 100gb of pics

    I have about 100gb of photos in about a dozen different iphoto albums. I split them up because I was running out of disk space and needed to offload some. Now I have a much larger hard drive. What is the best way to manage this volume of pics? IPhoto? Is there some other management system that may be worth considering? Does it make sense to keep that many photos in one library, or to split them up by broad categories?

    For managing large number of photos with speed there are a number of 3rd party DAM (digital asset management) applications, both consumer and professional. You can learn about the pro apps at The DAM Forum.
    I useMedia Expression which can handle 128K photos per catalog. You setup and maintain the folder configuration. Multiple catalogs can be scanned for photos with the search results displayed in a new catalog window. Files can be renamed via EM and metadata written to the original files. It has some minimal editing capability built in also. Most of the pro apps have similar features. I use it for my photo management and iPhoto for projects like books, calendars, etc.
    For the consumer apps there's Photo Mechanic 4.6.2 and ACDSee Pro 1.1.148 to name just a couple.
    With iPhoto Library Manager managing multiple libraries you can copy photos between libraries while maintaining the metadata and keepsakes.
    Happy Holidays

  • Best way to manage "free shipping" products

    Looking for suggestions on how best to manage shipping charges at a product/MM level. For certain customer and product combinations we offer free shipping. What is the best way to manage this in master data?
    thank you!

    Not in Master Data but in Pricing settings. All you have to do is having a price condition that define your fright price, lets say ZFR1. This Condition will have associated an Access Sequence (ZFR1) that will contain a table (lets say 987) with the Customer information (whether you want to do a distinction customer by customer or you want to set an indicator at the customer master record to group several records, lets say in the field Shipping Conditions, where you can set the value Z1 - Chargeable and the same for materials, look for a field you can use for this purpose). The table 987 will have such values (among others that you may need), then in T-Code VK11 you create the Condition Record that fulfill the parameters to determine a fright cost for the customer.
    Include the Condition type ZFR1 into the Pricing Procedure you are using for your sales orders and there you go, every time a Chargeable customer is placing a Sales Order  with a Chargeable Material the system will determine the condition ZFR1 with the amount you set in Transaction VK11... or, depending on the properties you maintain at the Condition Type you can let the user that is taking the sales order to place the Fright Price manually.
    Hope it helps Cheryl !
    Saludos!!

Maybe you are looking for

  • Old printer/New mac

    I have an old LaserWriter Select 360 I would like to use with my new ProMac but I can't seem to "add a printer" through the Printer Utility program. I am using a Belkin parallel to USB adapter to connect to the Mac. Since Mac is plug & play, I was to

  • Need to install Snow Leopard--seems complicated.  Can I pay Apple store to do it?

    While I'm mostly a right brain  type (writer), I can still do a lot of semi-geeky on my Mac Book Pro and even recently figured out how to rescue my mother's iMac from the "death screen" by using some keyboard shortcuts after unplugging all her cords.

  • Rescued pictures were downloaded to my iPhone; Can't delete from folders

    We rescued 368 pictures from an Android phone that was damaged and downloaded to my iPhone and stored in folders...Photo Library, Saved pictures and DCIM.... Finally, I had tech rep at store copy them to a zip drive and I stored safely to my computer

  • General Problems with iMac 9,1 's

    There seems to be a disturbing trend as of the last two OS releases, Mavericks and Yosemite, and it involves a lot of iMac 9.1's.  You see a lot of reports of sudden shutdowns, kernel panics, graphics issues, Safari crashes, Messages woes...and the l

  • [Prevending fraud] Can someone help with ARMv6 assembler?

    Hey, This year I started at university and one of my current courses require me to program some simple applications in Assembly (IA-32 variant). As a bonus exercise, my partner and I are redoing all the exercises in a different architecture. We chose