Image Filename - Relative Location

Hi, I am a pretty new programmer, and ran into a situation where I feel pretty stuck. I have a program that involves putting an image on the screen. Currently, I have a static filename: "C:/Program Files..." I want to be able to move a folder with my program and the image around onto multiple computers, but I don't want to have to change the filename every time I do so. Imagine that my the java file is in the same folder as the picture. Is there a method I can call to retrieve the location of file I am running? (If it matters, it is an application)
Please let me know if there is any more information i need to provide.
Thanks in advance for any help you can give.
private class MainPanel extends JPanel {
     public void paintComponent(Graphics g) {
          super.paintComponent(g);
          Graphics2D g2D = (Graphics2D)g;
          Image i = Toolkit.getDefaultToolkit().getImage("C:/Program Files/Folder/Picture.jpg");
          g2D.drawImage(i, 100, 210, this);}

There is a class called Class which has a method getResource(). This method returns a URL based on the name you supply as an argument. This URL can be used to load resources like images - for instance there is a version of the toolkit getImage() method that uses a URL rather than a filename.
http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResource(java.lang.String)
http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#getImage(java.net.URL)
The API documentation describes precisely how resources are found but, roughly speaking, they are located in the same place as the class file. This can "move around", or even be placed inside a jar file and the image will still load.
Class provides a static method that lets you get an instance of Class (to load resources with) based on the class name: likeClass cls = Class.forName("MainPanel");Or you can use getClass() with an instance of a particular classpublic void paintComponent(Graphics g) {
    super.paintComponent(g);
    Image i = Toolkit.getDefaultToolkit().getImage(getClass().getResource("Picture.jpg"));
    // etc
}(Haven't tested this - and I don't think you should really load the image every time paintComponent() is called. All sorts of exceptions can be thrown, so you may want to break that long line up a bit.)
http://www.exampledepot.com/egs/java.lang/GetClass.html

Similar Messages

  • Importing PSDs and TIFs with same image # as related RAW

    Before I got LR4 I developed a series of images (thousands) with Bridge and Photoshop.  I've now decided to build a LR catalog of the series.
    As I import I want to use the Image # option to rename files, making the whole mess of photos "cleaner" with unique names, etc.  Of course I want ot import Raw's and the Tif/Psd images I made along the way.  I notice the Image numbering process does NOT recognize the relationship between the raw and edited files.  So files (img_123.nef and img_123.tif) become (img-01.nef and img-02.tif).  I would prefer the tif file be named img-01.tif so the link between the two remains obvious.
    Is there a way to make this happen?  Key to creation date & time? 
    I realize this is a really specific issue, but if the point is to make the series tidier and more coherent it would be a useful feature.
    Thanks in advance.

    Date and time works, but it's a little indirect and you can't so easily search for this. You can IIRC extract just the numerical part of the original image filename, and build that into your renaming options - maybe along with a sequence number to impose uniqueness. This should be buried inside all versions derived from the same original capture, at least by default.
    As one example, you could get maybe ... 00024-img121.nef, 00025-img122.nef, 00026-img122.tif, 00027-img122.tif, 00028-img123.nef ... - if you had two added TIF edits of the image with 122 in its original name, as well as an original Raw of 121, 122 and 123. A text search for "img122" would then find all related versions.

  • Mobile Home Directory: Setting a relative location for various sub-nets

    Question Summary:
    1) Is it possible to define a home directory for mobile account users that is relative to the host's subnet?
    2) How does one accomplish #1 if possible?
    Details
    Setup
    Users access hosts on three LAN networks connected through the WAN via Branch-Office VPN connections (persistant VPN tunnels that connect our LANs)
    If User1 from LAN1 travels to LAN2, User1 has difficulty working, because the mobile account definition points to a host on LAN1 for HomeDirectory syncing, so all files are synced across a slow (5Mb/s) connection shared by all other users.  For some users (The CEO, for example), this sync entails transferring Gigs of personal data, so the Mobile Sync across the VPN literally takes several days, if it completes at all.
    My ideal setup would allow User1 from LAN1 to access a host at a relative location as apposed to an absolute location.  In other words, if LAN1 has the home folder at 192.168.76.23:/HomeFolders/User1, then when User1 moves to LAN2, the HomeFolder becomes 192.168.78.23:/HomeFolders/User1. Regardless the subnet, the User account would be defined in such a way that the HomeFolder would be sought at 192.168.X.23:/HomeFolders/shortUserId
    These home folders between the hosts 192.168.76.23 and 192.168.78.23 on LAN1 and LAN2, respectively, could be kept in sync during off hours so that at the beginning of each shift, all files are in all three locations ready for local use, fast access, and more importantly, fast home-syncing during the work day.
    Equipment
    OS X Yosemite running on various iMac and MacBook hardware configurations.
    OS X Server 4 running OD replicas and local DNS's on each LAN.
    Ample space for redundant data storage on all networks.
    Question
    How do I define a HomeDirectory as a relative location to the Mobile Account Users host machine or host machine IP address?
    Alternatively, is there a way that I can define a HomeDirectory using a Fully Qualified Domain Name so that I can use the local DNS server to force the redirect?
    Previously Tried Idea(s)
    Using the same Bonjour Computer Name
    On one test, I tried to trick the system by setting the name of the HomeDirectory computer to the same name on all networks. The thought behind this is that, when looking at the HomeDirectory path, the address is defined by the computer name, so if the local computer name matches, the system will automatically point to the host that is on the current LAN, as apposed to the host of the same name on the previous LAN.
    This failed due to the fact that the system providing the HomeDirectory storage is the same system that is providing OD replica services, and OD replication requires that each system have a unique name.

    Hi,
    Yes my home directory is set
    more /etc/passwd
    sfsys1d:x:301:201:sys1 dev sftp user:/interfaces/dev/system1:/usr/bin/csh
    when i log in they go to this directory, through a shell and through ftp ( haven't checked sftp yet)
    However i can still go up directories and see what is in the directories above
    the permissions are set as below
    drwx------   3 root
    sshusers  
    3 Sep  6 08:38 interfaces
    drwx--x---   3 root
    sshusers  
    3 Sep  6 15:49 dev
    drwxr-----   5 sfsys1d sshusers  
    7 Sep 19 14:52 system1
    I have tried various other permission 700, 710, 740 etc and they all give different results but not the correct one.
    The best I have managed to get so far is that they cannot list the files in the other directories, however if they know the names they can still go to them,  this also didn;t work in the windows ftp client, as it just showed the file/dirs anyway.
    Thanks
    Kerry

  • How do I resequence image filenames in an iPhoto event?

    My system configuration:  iMac i7 (2013), OS X Yosemite 10.10.1, current iPhoto app,  all updates installed, and iPhone 6 Plus.
    Within an event in iPhoto on my iMac, I have 300 photos.  I have taken photos at various times within a two year period.  After taking the photos I imported them into the iPhoto event whenever it was convenient.  Now I have many photos in that particular event that have various unsequenced image file names such as IMG_0250, IMG_0262, IMG_0271, etc, etc.  I am worried that sometime a photo that I take with my iPhone 6 Plus will have a duplicate image filename again such as IMG_0262.  I do not want the duplicate IMG_0262 on the iPhone to overwrite the previous IMG_0262 file on the iMac.  Since my photo filenames are unsequenced, I would like to sequence them and begin their names with IMG_0001, IMG_0002, etc, etc.  I resequenced the image names once before in another event, but do not remember the procedure I used.  Can someone please assist this old man.  Thanks

    1. These are filenames created by your camera, not image titles.
    2. A new photo with the same name will not ever overwrite another one. The file management on iphoto is smarter than that.
    3. You can change the title of a photos using the Photos -> Batch Change command.

  • Why doesn't Photos display image filename?

    Updated to Photos but found that whereas before one could display information beneath each image now there is no way to show the filename or the date of a picture. Over the years I have changed image filenames so that I can quickly find specific images and having the dates visible makes for easy classification without having to create loads of albums etc etc and then move stuff around. It would be nice if Apple didn't remove functionality when replacing software.

    Because there is no need for the file name - it is of no use
    and if you have been using iPhoto you have never changed a file name
    By default both iPhoto and Photos set the title to the file name if there is no title in the MetaData - but changing the title has no effect on the file name - in either program it is not possible to change file names
    In Photos you can see the title in the info window - if you want it below the photo request that apple add that option
    LN

  • Photos do not show in Messages - Only show as image filename

    For a long awhile now on Messages has not been handling images sent to me properly.
    All that shows up on Messages on my MBP (now running Yosemite) when someone sends me a message is the image filename (example: IMG_0456), with a little Preview icon to the left.
    Before the image used to show up on my Messages app on the MBP. Now, even clicking to open the image filename, just brings up a little dialog box with a larger Preview icon and the size of the image.
    In order to view images sent to me, I have to check them on my iPhone.
    I was hoping the Yosemite upgrade would fix this, but it seems to not have, and numerous searches for answers brings up no results. I have no idea when this started as it happened awhile ago.

    I have an early 2014 MBP (4th gen i7, 16 GB of RAM, IRIS Pro graphics) and am having the same issue. Attachments that could show previews displayed properly in Mavericks. If someone sent me a video, I could watch that video inline. If someone sent me a picture, I could see a preview right in the messages window, and double-click the image to view it at full-size / potentially open in Preview if I wanted to. Now, after upgrading to Yosemite, I too only see the filename of the attachment, and if I double-click it, a window displays with the filename, file type, and date created.
    This is obviously a problem.
    Has anyone figured out a way to fix this issue?
    Screens --
    Message received in Messages app: https://www.dropbox.com/s/ovoi3wjy9uldpah/Screen%20Shot%202014-10-26%20at%204.20 .55%20PM.png?dl=0
    Modal window showing attachment details: https://www.dropbox.com/s/g7s0wke719dprbx/Screen%20Shot%202014-10-26%20at%204.21 .20%20PM.png?dl=0
    Thank you guys for your time!
    --Mitch

  • How to set "same relative location" as default

    Currently my default is set "current users desktop"
    but can I change this setting to "same relative location
    so each time I open ARD I don't have to change this?
    Thank you,
    todd

    I've not been able to find a way, though putzing with Automator makes me think there is a way to create a workflow where you choose the desired computer(s) in ARD and then run a copy workflow in which you've saved "Same relative location" as a parameter.
    Perhaps someone better schooled in Automator might take on the task.

  • Link image filename to text.

    Hi, I am making a catalog and I have it in a basic format. Image of product first, underneath it is ProductID + Price.  The image filenames are formatted with the d of the product. How can I link it so in my catalog where is says ProductID: to have a string or variable after so that it will auto. take the file name of the above product and put in the id without .jpg following. I have tried but there is not even one way I can think of other then a simple link to the text box and the image box, there should be a feature to create any variable you like.

    In the sample scripts there is one called LabelGraphics which might work as a starting point (I've never used it myself). You could then run a series (if more than one format is involved) of GREP Find/Change queries to remove the extensions from the file names.

  • CALLING A IMAGE FROM A LOCATION OF SERVER

    Hello to all,i have 2 doubts:
    1ª) try to do this by creating a dummy image and then i format picture and put url{var} where var is in xml element and contains the path of the picture but doesnt work. i'm doing something wrong?
    2º) sometimes i want to call an image without the dummy because i'm limited to the size of the dummy image and if i have pictures in vertical and other in horizontal the aspect isnt quite good. i have a xsl command that i can call an image from a location (contained in a xml element )and resize it at runtime?
    Thank's in advance

    For 1a) what is the code that you are using? Have you followed the process like this blog post: http://blogs.oracle.com/xmlpublisher/2006/05/dynamic_images.html
    Thanks!

  • Geotagged iPhone Images lose exif location data

    Geotagged iPhone Images lose exif location data when emailed or IM'ed to an email address.
    I would like to have the option of sending this data (even if not by default) to the recipient.
    This feature seems to work on android and I am receiving this data in my inbox from an Android phone. The last thing I want to tell my customers is that the system I am building for them is only compatible with the Android because of this bug.
    Product roadmap information or workarounds are greatly appreciated.
    Thank you.

    Thanks for the quick response.
    There are some other apps that allow for exporting Geo Data to SMS (one example is called "GeoDataToSms" iirc). I'm subtly disappointed that third party apps would be the only solution here. I can build an app, but its adding complexity that I would rather not be worried about.
    I want my audience to send an email or SMS to an email account. That simple. The emails are then collected and the information from the message (images, exif data) is recorded in a database. When an admin visits the site they can see each image in a map and act on it. Stupid simple right?
    I think being able to email full blown photos is good enough for this round. But I think the expectation for most users (that even know geo data exists) is that geo data will be sent no matter the chosen image size. The same imo is true for SMS. I just have to limit the expectations when my users are on an iPhone. I can build an app that handles geolocation data in round twelve. And just let my iPhone audience know that their devices' cool features are limited by the software that powers them.

  • URIs for a relative location

    Hi,
    I'm not sure where to post this, but I'll try here.
    I have a URI that points to a relative location: URI myUri = new URI("resources/myFile.xml");
    When I deply my application to Tomcat the location is relative to tomcat/bin. so it would be tomcat/bin/resource/myFile.xml.
    I was hoping for [TOMCAT_HOME]/Webapps/myWebApp/classes/resources/myFile.xml or something like that.........
    Anyone know if my use of URI's is correct in this instance?

    I am not near a testable instance of Tomcat, but is there a reason you're using relative paths? Can you use an absolute path of /resources/myFile.xml? IIRC (and I might not) that will land you in the subdirectory you posted

  • Applescript image filenames to spreadsheet

    I'm a long time mac user but just recently discovered Applescript, TODAY! Looks amazing so far but I need some help to accomplish a simple (I think) task.
    I have a spreadsheet in numbers full of products (sku, price, blah blah blah). I have a folder full of images for all these products. The images are titled beginning with the sku followed by extra info like a _1 or _detail or -closeup etc.
    I want to basically create a script that will go through this spreadsheet, look at the SKU in each row, then find all the related image files within a specific folder (folder has subdirectories) and insert all matching filenames into a column next to the SKU, separated by a semicolon.
    For example,
    sku
    gallery_images
    abcd1234
    abcd1234.jpg;abcd1234_1.jpg;abcd_detail.png;abcd_closed.gif
    defg5678
    defg5678.png;defg5678_2.jpg;defg5678-lifestyle.jpg
    hijk91011
    hijk91011.jpg;hijk91011-2.jpg;hijk91011-5.jpg
    Any and all help would be much appreciated.

    I tried this here with a sample folder.... seems to work...
    so you select the lines you want to process with the script (columns sku and gallery_images) and the script overwrites the cells in "gallery_images" column with all found filenames....
    --14.09.2011 hubionmac.com
    -- parts of numbers selection code by http://hints.macworld.com/article.php?story=20090109055630154
    -- requested @https://discussions.apple.com/thread/3325583?tstart=0
    -- this script takes the value of a selection in numbers first and a asks for a folder
    -- then the values of the first column of the selection are taken and all filenames of start start with that folder and are found in the defined folder will be
    -- writen to the last column of the selection ----> you will have to select at least 2 columns
    set thefolder to quoted form of POSIX path of ((choose folder) as alias)
    tell application "Numbers"
    activate
    tell document 1
    -- DETERMINE THE CURRENT SHEET
    set current_sheet_index to 0
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of (tables whose selection range is not missing value)
    end tell
    if x is not 0 then
    set the current_sheet_index to i
    exit repeat
    end if
    end repeat
    if the current_sheet_index is 0 then error "No sheet has a selected table."
    -- GET THE VALUES OF THE SELECTED CELLS
    tell sheet current_sheet_index
    set the current_table to the first table whose selection range is not missing value
    tell the current_table
    set range_column_count to count of every column of selection range
    set this_rows_first_cell_index to 1
    set this_rows_last_cell_index to range_column_count
    -- THIS CHANGES THE VALUE OF
    repeat with i from 2 to count of every cell of selection range
    set thename to value of cell this_rows_first_cell_index of selection range
    set foundfilenames to my find_filenames(thefolder, thename)
    set value of cell this_rows_last_cell_index of selection range to foundfilenames
    set this_rows_first_cell_index to this_rows_first_cell_index + range_column_count
    set this_rows_last_cell_index to this_rows_last_cell_index + range_column_count
    if this_rows_last_cell_index > (count of every cell of selection range) then exit repeat
    end repeat
    end tell
    end tell
    end tell
    end tell
    on find_filenames(thefolder, filename_start)
    -- THIS SEARCHES FILES STARTING WITH A SPECIFIC STRING IN THEIR NAMES AND OUTPUTS JUST THEIR FILENAMES
    -- IS SEARCHES IN THEFOLDER AND ALL SUB-DIRECTORIES
    set theoutput to do shell script "find " & thefolder & " -iname \"" & filename_start & "*\" -exec basename {} \\;"
    if theoutput ≠ "" then
    set theoutput to every paragraph of theoutput
    set AppleScript's text item delimiters to "; "
    set theoutput to theoutput as text
    set AppleScript's text item delimiters to ""
    end if
    return theoutput
    end find_filenames

  • Firefox saves images to wrong location, but only when using "View Image"

    For a while, I have had the problem above. I can save images just fine if I don't use the "view image" function first, with the images going to the intended folders.
    Just to clarify, unlike some of similar problems I have seen described here, I am perfectly happy with Firefox remembering where I wish my pictures to go, on a site to site, or model to model (within the same site) basis.
    The problem lies in that if I use the "view image" function, either in a new tab, or in the existing one, Firefox will often prompt me to save in a random folder where I have previously saved a picture. It will even suggest folders that I have not accessed for days.
    Example:
    I save image A to folder A, by right clicking the image and selecting "save image as".
    I then (immediately after this), right click image A again, select "view image", then right click the resulting picture, and select "save image as". Now there is a fine chance that it want me to save the image to some other (previously used) image folder, even if I have not used the folder for a while, and even though I have just saved the same image to folder A.
    This problem persists with multiple image file types, on multiple sites (I just tried it with someones avatar in this forum, and it wanted me to put it with my holiday pictures from 3 weeks ago).
    I appreciate any assistance you can give - jinxie
    FYI; If I "one-click" a file (like an mp4) to download it, it goes to my main / default download folder as normal.

    This is because Firefox will track where you have saved images or other files from the website domain. Then whenever you select to save the file to your computer, Firefox will start the Save As wizard in the latest folder that you have used last time.
    Here is an example:<br>
    If you save an image from the domain <code>123.com</code> into the folder <code>123</code> it will save there. Then you save an image from the domain <code>456.com</code> to the folder <code>456</code>. Next you save a different image from the domain <code>123.com</code>. The save as wizard will assume that you want to save it with the other image from that domain and will automatically start in the <code>123</code> folder.<br>
    This can make saving files faster and more organized, however not everyone wants this feature enabled.
    To disable this feature you can do the following:
    #Go to <code>about:config</code> in Firefox
    #Locate the <code>browser.download.lastDir.savePerSite</code> string
    #Change the value to <code>false</code>
    This should fix the issue, but please report back if it doesn't.

  • How to load a PNG image from a location in CF card

    Hi,
    I am using WTK 2.5.2. I wanted to load a PNG image to Image object. The image is loaded when I have it in the classes folder. But I want to select different image from a different location. If I try to open an Image to createImage(String) from a different location, I get IOException.
    Please help me.
    Thanks
    Deekshit M

    I got the answer, I should be using Image.createImage(InputStream) API. It works fine.
    Thanks
    DM

  • How to get image filename in indesign cs3

    Hi,
        I want to get a filename of a selected rectangle frame graphic child item like tiff image or pdf file. Please help me with a code snippet.
    Thanks,
    K.Saravanan.

    app.activeWindow.activeSpread = myDocument.spreads[j];
    app.activeWindow.zoom(ZoomOptions.FIT_SPREAD);

Maybe you are looking for