Filename for ImageIcon

Hi all
How to avoid hard coding the absolute path for the argument for ImageIcon ?
For example :
ImageIcon icon = new ImageIcon("c:\\img\\help.gif");
Thank you

I have written the following class which works for me:
import java.io.*;
import javax.swing.*;
import java.net.*;
import java.awt.*;
import java.util.HashMap;
public final class ImgLoader {
  private static HashMap imageMap = new HashMap (20);
  private ImgLoader() { }
  public static Image loadImage (File image) {
    return loadImage (image.getAbsolutePath());
  public static Image loadImage (String imageName) {
    return loadImage (imageName, false);
  public static Image loadImage (String imageName, boolean useCache) {
    ImageIcon icon = loadIcon (imageName, useCache);
    if (icon != null)
      return icon.getImage();
    else
      return null;
  public static URL getResource (String imageName) {
    final String location;
    URL url;
    if (imageName.charAt (0) == File.separatorChar || imageName.charAt (1) == ':')
      location = imageName;
      // full path
      try
        url = new java.io.File (location).toURL();
      catch (MalformedURLException e)
        Logger.log (e);
        url = null;
    else
      location = "pics/" + imageName;
      // relative path
      url = ImgLoader.class.getResource (location);
    return url;
  public static ImageIcon loadIcon (File imageName, boolean useCache) {
    return loadIcon (imageName.getAbsolutePath(), useCache);
  public static synchronized ImageIcon loadIcon (String imageName, boolean useCache) {
    final URL url = getResource (imageName);
    if (url != null)
      if (imageMap.containsKey (imageName))
        return (ImageIcon) imageMap.get (imageName);
      else
        final ImageIcon icon = new ImageIcon (url);
        if (useCache)
          imageMap.put (imageName, icon);
        return icon;
    else
      Logger.log ("Warning: icon '" + imageName + "' not found");
      return null;
  public static synchronized ImageIcon loadIcon (String imageName) {
    return loadIcon (imageName, true);
}You can put this class inside some package if you want. In order for this class to work, you need to place all images in a directory calls "pics".
Your directory tree could look something like this:
. <-- root
|
+ ImgLoader.java
+ pics
| |
| + print.gif
| + .. etc ..
+ .. etc ..You then use this class by calling:
ImageIcon icon = ImgLoader.loadIcon("print.gif");Good luck

Similar Messages

  • Infospoke - How to single Logical Filename for all infospokes

    Hello all,
    I want to only have one logical path and logical filename for all of my infospokes.
    For example if I have infospokes ZAAA, ZBBB, ZCCC, I want to have only one common setting in the destination properties of TC:RSBO but three different distinguishable files on my OS.
    I think with the standard settings, I have to make one logical file for every infospoke I have.
    I am aware that I can put <DATE> or <TIME> etc in the logical file settings but that will not distinguish which infospoke the file came from.
    I want my file to look more like <INFOSPOKE>_<DATE><TIME>.csv
    I've already seen the document "How to Extract Data with OPEN HUB to a Logical Filename"  and this is not it because I have BW3.5 and 3.5 already does what this article says.
    Any help would be greatly appreciated.
    Just in case, I am on BW3.5 SP17 on Windows/SQL.

    Jasprit,
    Thanks for your input.
    The functionality of the FM you said is similar to the InfoSpoke functionality...
    Is it the same thing?
    I wonder if I use this it means it is not part of the InfoSpoke license...
    I will have our programer look at it and see what he thinks but in the mean time any other information is greatly appreciated.  Especially if I can stick with using the standard InfoSpoke functionality...
    Isn't this kind of functionality something that everyone wants?
    I wonder why SAP didn't make it like this?

  • I need to start and stop logging based on a digital input event(or analog if necessary), log data for several seconds prior to the event, and have the data file close at the end of event and increment the filename for the next logging event.

    I don't know if this can be done with VI Logger or need to use Labview V7.1.

    After browsing through the VI Logger User Manual, it looks like the triggering that you are hoping to accomplish is possible. However, incrementing the filename for the next logging event is not going to be possible. VI Logger does exactly what its name tells - logs data. I don't think the automation that you are hoping to accomplish is possible.
    For help with setting up your application, if you do choose to stay with VI Logger, make sure to chek out the Getting Started with VI Logger Manual.
    Best of luck.
    Jared A

  • "E_PACK_ERROR: illegal filename for a PUT" Error in Packaging a PDF file

    Hi Jim,
    As per ContentServer_Technical_Reference.pdf (page no 9) I passed <filename>, <location> and <src> parameter in our packaging request xml. File is packaging successfully and service is also placing the encrypted file to new location listed in <location> but following error is comming:
    <error xmlns="http://ns.adobe.com/adept"
    data="E_PACK_ERROR http://myserverurl/packaging/Package illegal%20filename%20for%20a%20PUT"/>
    My Packaging XML:
    <package xmlns="http://ns.adobe.com/adept" action="add">
    <fileName>9781591439745.pdf</fileName>
    <location>ftp://username:password@myserverurl/www/folder/9781591439745.pdf</location>
    <src>http://myserverurl/folder/9781591439745.pdf</src>
    <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:title>9781591439745</dc:title>
    <dc:creator>Nicolya Christi</dc:creator>
    <dc:format>application/pdf</dc:format>
    <dc:publisher>Work Disribution System</dc:publisher>
    <dc:language>en</dc:language></metadata>
    <permissions><display/><excerpt/></permissions>
    <dataPath>C:/folder/9781591439745.pdf</dataPath>
    <expiration>2011-03-02T15:18:02+05:30</expiration>
    <nonce>LTIyNzc1Mjk4</nonce>
    </package>
    Please suggest me why the "E_PACK_ERROR http://myserverurl/packaging/Package illegal%20filename%20for%20a%20PUT" error is comming.
    I am waiting your reply...
    With regards,
    Mangal Varshney

    Hello Jim,
    I tried as you suggest not to use all three, filename, location and src. I removed the <filename> parameter from packaging xml and then try to package the same error are comming again. Jim this same code was working earlier, we are using same on our production sever till now but suddenly it stop working.
    "E_PACK_ERROR: illegal filename for a PUT"
    I checked the packaging.log file, the log message are:
    02 Mar 2011 05:41:56,673 TRACE AdeptServlet: request POST http://myserverurl/packaging/Package
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection: Open jdbc:mysql://127.0.0.1:3306/adept with user=dmr_mysql_dba
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection: SELECT distid, name, description, disturl, notifyurl, publickey, sharedsecret, maxloancount, linkexpiration FROM distributor WHERE distid = ?
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 1 = 00000000-0000-0000-0000-000000000001
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection: rollback
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection: SELECT distid, nonce, expiration FROM distusednonce WHERE distid = ? AND nonce = ?
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 1 = 00000000-0000-0000-0000-000000000001
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 2 = [B@6c2a78
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection: INSERT INTO distusednonce(distid, nonce, expiration) VALUES(?, ?, ?)
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 1 = 00000000-0000-0000-0000-000000000001
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 2 = [B@6c2a78
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 3 = Wed Mar 02 06:41:56 CST 2011
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection: DELETE FROM distusednonce WHERE expiration < ? AND distid = ? AND nonce = ?
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 1 = Wed Mar 02 05:41:56 CST 2011
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 2 = 00000000-0000-0000-0000-000000000001
    02 Mar 2011 05:41:56,673 TRACE DefaultSQLDatabaseConnection:   obj 3 = [B@6c2a78
    02 Mar 2011 05:41:56,689 TRACE DefaultSQLDatabaseConnection: SELECT resourceid, item, description, title, publisher, creator, language, identifier, thumbnailurl, format, src, downloadtype FROM resourceitem WHERE src = ? AND downloadtype = ?
    02 Mar 2011 05:41:56,689 TRACE DefaultSQLDatabaseConnection:   obj 1 = http://myserver2url/folder/9781591439745.pdf
    02 Mar 2011 05:41:56,689 TRACE DefaultSQLDatabaseConnection:   obj 2 = simple
    02 Mar 2011 05:41:56,876 ERROR Package: Error in packaging
    java.io.IOException: illegal filename for a PUT
        at sun.net.www.protocol.ftp.FtpURLConnection.getOutputStream(Unknown Source)
        at com.adobe.adept.packaging.servlet.Package.aquireLocationStream(Package.java:359)
        at com.adobe.adept.packaging.servlet.Package.doPost(Package.java:535)
        at com.adobe.adept.packaging.servlet.Package.doPost(Package.java:43)
        at com.adobe.adept.servlet.AdeptServlet.doPost(AdeptServlet.java:184)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProto col.java:579)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
        at java.lang.Thread.run(Unknown Source)
    02 Mar 2011 05:41:56,876 TRACE DefaultSQLDatabaseConnection: rollback
    02 Mar 2011 05:41:56,907 ERROR AdeptServlet: request error [myip]: E_PACK_ERROR http://myserverurl/packaging/Package illegal+filename+for+a+PUT
    02 Mar 2011 05:41:56,907 TRACE AdeptServlet: request end http://myserverurl/packaging/Package
    Please debug the above message and suggest me what i will do to rectify this issue.
    With Ragards,
    Mangal Kumar

  • How do I change filename for single-image HTML pages in web gallery for LR 3

    Hi,
    I would like to change the default filename for the HTML pages produced by Lightroom 3 in the web gallery. Specifically, I would like to remove the string "_large" from the HTML filename, so it corresponds exactly to the image filename.
    Specifically, the URL by default is like this:
    http://www.mysite.com/content/_c_EMT2146_large.html
    and I would like it to be like this
    http://www.mysite.com/content/_c_EMT2146.html
    I assume there is some way to make this change using the template editors, but I can't figure it out.
    thanks,
    James Riemermann

    Turns out there's a fairly easy way to change that on Windows, but I can't figure out an equivalent on a Mac, which is where the need is. On windows, I can edit (after backing up) the following two config files:
    C:\Program Files\Adobe\Adobe Photoshop Lightroom 3.6\Shared\webengines\default_html.lrwebengine\grid.html
    C:\Program Files\Adobe\Adobe Photoshop Lightroom 3.6\Shared\webengines\default_html.lrwebengine\manifest.lrweb
    In which the "_large" string is appended and can be removed, following which the gallery works exactly as I would hope.
    But I can't find the equivalent files on the Mac, though I would assume they exist.

  • How to set the AS2 fileName for outbound Functional Ack 997 auto generated by Oracle B2B

    Hi Friends,
    How to set the AS2 fileName for outbound Functional Ack 997 auto generated by Oracle B2B.
    External Trading Partner is sending the EDI 856 via AS2 URL to our Oracle B2B Server.
    In the inbound 856 agreement, we have checked the option of Funtional Ack and also Functiona Ack handled by B2B is yes.
    We have the outbound agreement which is sending that Functional ack 997 (auto generated by oracle b2b) and we have specified the Outbound AS2 channel of the Partner.
    997 doc is being sent to external partner using AS2 channel, but the filename is generating as '40101'.
    Please can you let me know how to set the AS2 fileName for outbound Functional Ack 997 auto generated by Oracle B2B.
    Appreciate your valuable answers!!
    Thanks,
    Amirineni

    Amirineni,
    AFAIK, there is no option to set the file name when the 997 is generated automatically by B2B.
    Alternatively, if this is a must requirement, you can generate the FA from backend and  send to B2B with MSG_TYPE =9. In this case, you can set the header with filename (How to set the actionname property in B2B 11g)

  • Dynamic filename for stdout from cron

    OL 5.6 x86-64
    I'm looking for a way to dynamicly specify a filename for stdout from a cron job.
    From a command line, this works fine:
    /home/estevens/bin/x1 > /tmp/estevens_x1_log.`date +%F_%H%M%S`Producing the desired output:
    estevens:dwdev$ ls -ltr /tmp/est*
    -rw-rw-r-- 1 estevens estevens 96 Aug 13 10:23 /tmp/estevens_x1_log.2012-08-13_102356But when I put that in my crontab:
    12 * * * 1 /home/estevens/bin/x1 > /tmp/estevens_x1_log.`date +%F_%H%M%S`I get this result
    /bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
    /bin/sh: -c: line 1: syntax error: unexpected end of file(Result comes to me in an auto-generated email)

    The % sign has a special meaning in cron. A % is used to denote a new line in a crontab entry. You will simply have to escape the % signs and it should work, for instance:
    <pre>
    12 * * * 1 /home/estevens/bin/x1 > /tmp/estevens_x1_log.`date +\%F_\%H\%M\%S`
    </pre>

  • Custom Filename for Export Data from a Query

    Hi,
    Would like to define a custom filename for the file to be download as a csv from the web query, Is it possible?
    Regards
    Chocks

    This is not possible, it will be system generated.

  • Framemaker uses $filename for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen?

    Framemaker uses <$filename> for short file name, can we edit this to change appearance? We do not want the short file name of long filename to include the .fm extension can this be removed or modified to make this happen? In compiling our books it would be helpful to not have this extension appear as it then requires us to create extra files without them.

    See: System Variables

  • Restore - filename for datafile is missing in the control file

    I am practicing RMAN recovery procedures and I encountered a problem that I do not know how to solve.
    1) I took a hot backup of my test database.
    2) Create tablespace TS_DATA_TEMP
    3) Deleted tablespace TS_DATA which had 2 datafiles
    4) Created tablespace TS_DATA with 1 datafile
    5) shutdown database
    6) logged into RMAN in nomount
    7) restore controlfile from autobackup;
    8) alter database mount;
    9) restore database;
    RMAN> restore database;
    Starting restore at 22-AUG-08
    using channel ORA_DISK_1
    the filename for datafile 5 is missing in the control file
    skipping datafile 1; already restored to file /u02/oradata/EDM91/system01.dbf
    skipping datafile 2; already restored to file /u02/oradata/EDM91/undotbs01.dbf
    skipping datafile 6; already restored to file /u02/oradata/EDM91/index
    skipping datafile 3; already restored to file /u02/oradata/EDM91/sysaux01.dbf
    skipping datafile 7; already restored to file /u03/oradata/EDM91/TS_INDEX01.dbf
    skipping datafile 9; already restored to file /u03/oradata/EDM91/TS_LOB01.dbf
    skipping datafile 4; already restored to file /u02/oradata/EDM91/users01.dbf
    restore not done; all files readonly, offline, or already restored
    Finished restore at 22-AUG-08
    10) tried to recover
    Starting recover at 22-AUG-08
    using channel ORA_DISK_1
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of recover command at 08/22/2008 15:04:22
    RMAN-06094: datafile 5 must be restored
    SQL> select name from v$datafile where file#=5;
    NAME
    /u04/oradata/EDM91/TS_DATA.dbf
    12) alter database backup controlfile to trace
    DATAFILE
    '/u02/oradata/EDM91/system01.dbf',
    '/u02/oradata/EDM91/undotbs01.dbf',
    '/u02/oradata/EDM91/sysaux01.dbf',
    '/u02/oradata/EDM91/users01.dbf',
    '/u04/oradata/EDM91/TS_DATA.dbf',
    '/u02/oradata/EDM91/index',
    '/u03/oradata/EDM91/TS_INDEX01.dbf',
    '/u04/oradata/EDM91/TS_DATA02.dbf',
    '/u03/oradata/EDM91/TS_LOB01.dbf'
    CHARACTER SET UTF8
    So i'm not sure what the problem is. Datafile TS_DATA.dbf is located in the control file but i'm getting the error: the filename for datafile 5 is missing in the control file.
    Suggestions on what's wrong with the control file?

    I found my mistake; a newbie error.
    I did not know I needed to include in my restore command the 'until' option when doing incomplete recovery. I only included the 'until' option in the recover command:
    original command
    restore database;
    recover database until sequence =123;
    should be
    restore database until sequence = 123;
    recover database until sequence =123;
    I usually run the command using a RUN block with a SET UNTIL SEQUENCE but this case I used the single commands separately.
    RUN
    +{+
    SET UNTIL sequence 123;
    RESTORE DATABASE;
    RECOVER DATABASE;
    +}+

  • OPEN DATASET FILENAME FOR OUTPUT.

    HI,
    While doing unicode enable inECC6.0 FOLLOWING ERROR IS COMING.hOW IT WILL BE RESOLVED.
    oPEN DATASET physname FOR OUTPUT.

    Hello,
    For opendataset u need to add the below coding.
    open dataset 'filename' for output in text mode encoding default. ( Based on ur filetype)
                                                            binary mode encoding default
    if it not a unicode system then non unicoding must be added.
    N.B
    In the Transfer stmt the data types apart from CNDT will result dump.
    So please ensure that all are of CNDT types.
    With Regards,
    Sumodh.P

  • Setting filenames for images sequences via scripting

    Is there a good way to set the output filename for a sequence via scriping? When I explicitly set the filename and render location, the frame number is being appended to the end of the extension. (example: "filename.png002").

    Did a quick test.
    You can set name the way you want "Comp 1-[#].jpg" - I mean if you add [#] by hand, AE seems to respect that.
    So I guess you could check how many frames you are going to render and set appropriate amount of # signs in the file name.
    Looking at your example, seems that AE ads frame number after the extension. In case you want to control where AE puts those frame numbers, try this "filename-[#].png" - that should do the trick.

  • Need to specify default filename for SaveAs

    I am using the command app.execMenuItem("SaveAs"); in the click event of a button. Is there anyway that I can specify a default filename for the user? I do want the user to get the Save As window and the ability to change the name if possible.
    The form is generated by the RenderForm Java script, and the name being generated as a default for the SaveAs window is RenderForm.pdf
    Thanks,
    Velvet

    Chris, I think you missed this one.
    I think you want to change the name when calling app.SaveAs via javascript from the client not on the server. Since app.executeMenuItem("saveAs") will not take any parameters to suggest a file name. I think you will have to use doc.saveAs which will allow the name to be specified. This would require a trustedFunction which may or will not work unless you have known users. You will also need to prompt for the file name before making the call.
    Here is some untested code to get you started...
    You will need to create a trustedFunction (see AcroJS.pdf for details) ..
    saveFunc = app.trustedFunction(function (filename) {
    app.beginPriv();
    try {
    event.target.saveAs({cPath: filename});
    } catch (err) {
    app.alert("Error: " + err);
    app.endPriv();
    Code for your event...
    var suggestedName = "MyPDFName.pdf";
    // Note This will only work if you know where they will be saving it
    var cPathToSaveTo = "/c/temp/";
    var cResponse = app.response({
    cQuestion: "What name would you like to use for this PDF?",
    cTitle: "File Name",
    cDefault: suggestedName,
    cLabel: "File Name:" })
    if(cResponse != null)
    saveFunc(cPathToSaveTo + cResponse );
    Hope this helps.
    Rich Ruiz
    Novanis

  • Passing a filename for Playsound()?

    Hi!I have to call a function inside a dll for pocket pc 2002 from labview7: the function contains Playsound, in fact I want my pocket pc to play a file.wav, the problem is passing the filename as a parameter..as a CStr?PlaySound doesn't recognize it!
    what's the right way to pass a string/filename for Playsound?
    thank you very much!!!
    Marta

    To call a DLL from your PDA application requires you do what is reported in THIS DOCUMENT. There are several steps to perform to make your code suitable for PPC.
    HERE you will find an example that shows what needs to be done.
    Passing the Filename parameter to the Playsound Function in Winmm.dll is pretty straightforward. Use StdCall conventions and use CString for file name.
    Regards,
    AlessioD

  • Passing EDI filename for 850 from B2B Gateway to BPEL

    Hi,
    Is there any way to pass the EDI filename for 850 from B2B Gateway to BPEL via AQ? we want to store the inbound filename in the database along with the PO.
    we are using 10g.
    Thanks,
    Naveen

    Hi Naveen,
    Generally this could be done using the message id only as mentioned by ew. Just what you need to do is to lookup in the table and find the payload corresponding to that message id.
    However, WORKAROUND would be to use "Preserve Filename" feature of 11g B2B (which works only for FILE,FTP and SFTP transport protocols). In this case you have to pass the filename in the header "ACTION", as mentioned by Nitesh.
    Regards,
    Anuj

Maybe you are looking for

  • How To Create Object Wrappers

    Hi there, I would like to implement some better and custom error handling in some of the business objects.  Objects such as the Recordset and Documents can have a tendency to 'die' on a line that errors and I would like to create wrappers for these c

  • BAPI or FM to create Invoice in SRM , without reference to PO ?

    Dear Colleagues, We have a situation where we have to create invoices in SRM from a file from a legacy system, that means we have no POs in SRM. Which process, BAPI or Function Module would you recommend me? Is it possible to create "standard" invoic

  • Buying a new Macbook Pro for music recording, should I upgrade the RAM or Processor?

    As the title states, I'm looking into buying a new Macbook (15 inch) for music recording. Should I upgrade the processor or the RAM memory?

  • Problems with screen freezing and going blank...

    Yesterday I was looking through photos that I had loaded on to my mac book (which I have looked through before and not had any probems) when all of a sudden everything froze and a spinning colour wheel appeared on the screen. I couldn't click on anyt

  • EWM Implementation project in SCM5.0

    Hello All, Is any one working on Extended Warehouse Management (EWM) implementation project in SCM5.0. If yes what is the Scope of the functionality of EWM? Regards, Anjali