How to use class.getResource() to create an ImageIcon

Hi,
I am well acquainted with creating and using ImageIcon icons using the ImageIcon constructor
and putting the image file in a folder called Images which is at the same level as the
bin and src folders.
I discovered a demo program, LayeredPaneDemo, that uses class.getResource() to create
an icon and found that in my eclipse version, the icon's image file was not found when
I used the original getResource() call but the icon was created when I used the ImageIcon
constructor.
I posted on JavaRanch and eventually realized that the image file needed to be with the
.class files, so I moved the Images folder under bin and getResource() works fine and I'm
happy.
However, I have three questions for you.
One poster on JavaRanch told me that it's better to use getResource() rather than the
ImageIcon constructor for distributing an app (I'm not distributing anything but want
to do it all correctly).
Do you agree with that or can I safe keep using the ImageIcon constructor?
Another poster told me he doesn't think it's safe to leave the image file in bin because
it might be lost during the build in eclipse and that there is a way to have eclipse copy
the files to bin during the build which should mean that I can leave the images folder at
the level of bin and src.
Do you agree with that?
If yes, how do I get eclipse to copy the file during the build?
P.S.
Before I posted on JavaRanch, I put the Images folder at every level of the project's
directory as shown in eclipse (which is why I missed the bin folder until JavaRanch
whacked me upside the head) and getResource() still didn't work.

The contents of the Java Source folder are compiled if they're source files, copied otherwise (assuming no filter's been put in place to prevent copying), so your images belong under a source folder.

Similar Messages

  • Need samples how to use classes in WebDynpro

    Hi,
    I Need To simple Samples how to use classes in WebDynpro.
    Regards

    Continued....
    and in the model
    right click->create model
    select the radio button import java bean .
    next ADD jars option will be seen
    Browse the jar on the dekstop.
    now add this model to the used models by right clicking on it.
    Now if you go to Data Modeler.
    You will find the used model.
    From there map to the component controller->view Controller.
    And continue with ur coding.
    Hope this helps you.
    Thanks & Regards,
    Lokesh.

  • How to use the DLLs which created from c++ in Java?

    And How to use the DLLs which created from JNI in C++?

    Huh?
    Are you asking how to do JNI - you should read the tutorial.
    Are you asking how to load it - then use System.loadLibrary()
    Are you asking what to do with the output from javah - put it in a C file and write some code, compile it into a dll.

  • How to use networkmanager-applet to creat wireless internet sharing?

    hi,
    I'm trying to creat a wireless connection to share internet with another laptop.
    I followed the usual step like how i did it on Ubuntu
    Creat New Wireless Connection-->
    then I setup a connection
    Mode: Ad-hoc  (No security password, cuz it's for testing)
    ipv4 settings: Method: shared to other computers
    when I tried to connect to this connection, it does work for only a second. the notify-osd says connection established, then changed into disconnected right after. and the connection does was detected on the other laptop (with vista), but only last about a second.
    I have no idea what happed. but it works perfectly on Ubuntu, with the same operations.
    also, if I create a connection on vista, it can connect to that connection.
    what should I do to make it works as well as how it does in unbuntu?
    # /etc/rc.conf - Main Configuration for Arch Linux
    # LOCALIZATION
    # LOCALE: available languages can be listed with the 'locale -a' command
    # HARDWARECLOCK: set to "UTC" or "localtime"
    # USEDIRECTISA: use direct I/O requests instead of /dev/rtc for hwclock
    # TIMEZONE: timezones are found in /usr/share/zoneinfo
    # KEYMAP: keymaps are found in /usr/share/kbd/keymaps
    # CONSOLEFONT: found in /usr/share/kbd/consolefonts (only needed for non-US)
    # CONSOLEMAP: found in /usr/share/kbd/consoletrans
    # USECOLOR: use ANSI color sequences in startup messages
    LOCALE="en_US.utf8"
    HARDWARECLOCK="localtime"
    USEDIRECTISA="no"
    TIMEZONE="Asia/Shanghai"
    KEYMAP="us"
    CONSOLEFONT=
    CONSOLEMAP=
    USECOLOR="yes"
    # HARDWARE
    # MOD_AUTOLOAD: Allow autoloading of modules at boot and when needed
    # MOD_BLACKLIST: Prevent udev from loading these modules
    # MODULES: Modules to load at boot-up. Prefix with a ! to blacklist.
    # NOTE: Use of 'MOD_BLACKLIST' is deprecated. Please use ! in the MODULES array.
    MOD_AUTOLOAD="yes"
    #MOD_BLACKLIST=() #deprecated
    MODULES=(acpi_cpufreq cpufreq_ondemand cpufreq_powersave usblp usbcore)
    # Scan for LVM volume groups at startup, required if you use LVM
    USELVM="no"
    # NETWORKING
    # HOSTNAME: Hostname of machine. Should also be put in /etc/hosts
    HOSTNAME="kwan-laptop"
    # Use 'ifconfig -a' or 'ls /sys/class/net/' to see all available interfaces.
    # Interfaces to start at boot-up (in this order)
    # Declare each interface then list in INTERFACES
    # - prefix an entry in INTERFACES with a ! to disable it
    # - no hyphens in your interface names - Bash doesn't like it
    # DHCP: Set your interface to "dhcp" (eth0="dhcp")
    # Wireless: See network profiles below
    #Static IP example
    #eth0="eth0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
    eth0="dhcp"
    INTERFACES=(lo !eth0 !ath0)
    # Routes to start at boot-up (in this order)
    # Declare each route then list in ROUTES
    # - prefix an entry in ROUTES with a ! to disable it
    gateway="default gw 192.168.0.1"
    ROUTES=(!gateway)
    # Enable these network profiles at boot-up. These are only useful
    # if you happen to need multiple network configurations (ie, laptop users)
    # - set to 'menu' to present a menu during boot-up (dialog package required)
    # - prefix an entry with a ! to disable it
    # Network profiles are found in /etc/network.d
    # This now requires the netcfg package
    #NETWORKS=(main)
    # DAEMONS
    # Daemons to start at boot-up (in this order)
    # - prefix a daemon with a ! to disable it
    # - prefix a daemon with a @ to start it up in the background
    DAEMONS=(syslog-ng hal fam cpufreq @laptop-mode ufw networkmanager dnsmasq netfs cups crond avahi-daemon !network !lastfmsubmitd !lastmp alsa gdm)
    [kwan@kwan-laptop ~]$ ifconfig
    eth0 Link encap:Ethernet HWaddr 00:13:A9:50:3D:2B
    inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
    inet6 addr: fe80::213:a9ff:fe50:3d2b/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:1628 errors:0 dropped:0 overruns:0 frame:0
    TX packets:1788 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:1061372 (1.0 Mb) TX bytes:276083 (269.6 Kb)
    Interrupt:16
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:694 errors:0 dropped:0 overruns:0 frame:0
    TX packets:694 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:34780 (33.9 Kb) TX bytes:34780 (33.9 Kb)
    wlan0 Link encap:Ethernet HWaddr 00:19:7D:C0:F8:5A
    inet6 addr: fe80::219:7dff:fec0:f85a/64 Scope:Link
    UP BROADCAST MULTICAST MTU:1500 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:90 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:0 (0.0 b) TX bytes:20024 (19.5 Kb)
    wmaster0 Link encap:UNSPEC HWaddr 00-19-7D-C0-F8-5A-00-00-00-00-00-00-00-00-00-00
    UP RUNNING MTU:0 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

    I can't get this to work either.  I've tried everything I can think of.
    Relevant configuration file:
    # DHCP configuration generated by Firestarter
    ddns-update-style interim;
    ignore client-updates;
    subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers 192.168.1.1;
        option subnet-mask 255.255.255.0;
        option domain-name-servers 128.253.180.2, 132.236.58.250;
        option ip-forwarding off;
        range dynamic-bootp 192.168.1.100 192.168.1.110;
        default-lease-time 21600;
        max-lease-time 43200;
    dnsmasq is installed and running.
    created ad-hoc network in nm-applet, tried all sorts of different configs in there to no avail.
    Has anyone gotten this working in Arch?

  • How to use migration assistant without creating dual user accounts

    I want to use migration assistant to transfer apps, software & files on my macbook pro to my new macbook air. How can I do this without creating two user accounts for myself on the m-book air -- my account from the m-book pro & the one that the air makes me create as soon as I do start-up? Can I just use the same name & password for both? or will that make things go badly awry?
    Thanks!

    If you have not booted the MBA for the first time and gone through the Setup Assistant, then I would use the Setup Assistant to make the transfer before you even create another user account. However, if you've already created the new user account on the MBA, then create a new admine one with a different username than the account you will migrate. Log into this new account, delete the first account you made, then use Migration Assistant to transfer your account from the MBP.

  • How to use Class "CL_GUI_CHART_ENGINE" in a abap program ?

    Hi Guys,
    I want to display data in my internal table in the form of a Graph using class "cl_gui_chart_engine".
    I had a look at sample program given by SAP - GRAPHICS_GUI_CE_DEMO but need some help to understand how can we use our own data to be displayed in the graph ? Basically what I am looking for is that where we need to do the changes in creation of XML file so that we can pass our own data ?
    ( perform create_data_demo using l_ixml_data_doc)
    Could you please help me with some sample code or pseudocode ?
    Thanks
    Ashwa

    Thanks Kai,
    I had already done the same thing and got the required output.
    Populate X-Axis ( Categories )
      LOOP AT ITAB.
    Populate Categories
        l_element = p_ixml_doc->create_simple_element(
                  name = 'C' parent = l_categories ).
        l_element->if_ixml_node~set_value( itab-value).
      ENDLOOP.
    Populate Y-Axis ( Values )
      LOOP AT VALUE_TAB.
       l_element = p_ixml_doc->create_simple_element(
                 name = 'S' parent = l_series ).
        l_element->if_ixml_node~set_value( value_tab-value).
      ENDLOOP.
    I am now trying to find the ways to change the default layout of the graph. I guess it should be done in "perform create_custom_demo using l_ixml_custom_doc." . I want that my graph should be displayed as lines instead of bar's.
    Once I achieve this I will share my findings along with sample code with the community.
    I wish I could get some documentation on class "cl_gui_chart_engine" and interfaces like "if_ixml_document".
    Thanks
    Ashwani

  • How to use classes of packages in flex mx:Script/ or mxml/

    Hi.I am just learning Flex using Flex Builder 3 facing one problem,
    Suppose I declare one package with name alert.as
    package
    import mx.controls.Alert;
    public class alert
    public function alertBtn()
    Alert("Hello btn 1");
    Now in want to use the function in mxml that I declared in a package.
    <mx:Button label="btn1" click="alertBtn();"  />
    I have few questions
    1)How to Import the class alert.as in <mx:Script> and where should i store the file alert.as in the directory folder of flex?
    2)How to call the function alertBtn() when btn1 is clicked.
    Thanks so much!
    Regards
    Ankur

    Hi Greg.I think I was not able to clear my problem properly.Let me try this time again.
    What I wanted to do was that in the below written code I have the full access of the id=panel1 in the  script tag .This works properly.
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script><![CDATA[
    import flash.display.Sprite;
    import mx.core.UIComponent;
    private function addChildToPanel():void {
    var circle:Sprite = new Sprite();
    circle.graphics.beginFill(0xFFCC00);
    circle.graphics.drawCircle(0, 0, 20);
    var c:UIComponent = new UIComponent();
    c.addChild(circle);
    panel1.addChild(c);
    ]]></mx:Script>
    <mx:Panel id="panel1" height="100" width="100"/>
    <mx:Button id="myButton" label="Click Me" click="addChildToPanel();"/>
    </mx:Application>
    This above functionality when I tried to do using class Outside the code ,its not working !
    Here is with the package:-
    But suppose I make One package 
    package
    import flash.display.Sprite;
    import mx.core.UIComponent;
    class getPanel extends Sprite
    public function addChildToPanel():void {
    var circle:Sprite = new Sprite();
    circle.graphics.beginFill(0xFFCC00);
    circle.graphics.drawCircle(0, 0, 20);
    var c:UIComponent = new UIComponent();
    c.addChild(circle);
    panel1.addChild(c);
              }//class
                        }//package
    Now in MXML
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script><![CDATA[
    import getPanel;
    ]]></mx:Script>
    <mx:Panel id="panel1" height="100" width="100"/>
    <mx:Button id="myButton" label="Click Me" click="getPanel.addChildToPanel();"/>
    </mx:Application>
    So My problem is that this code doesnt do anything.
    Neither the addChild function is working in it ,Nor the Panel1 is accessible here.
    Can u pls help me here.
    Thanks
    Ankur

  • How to use classes CL_DOCX_*

    We have a need to use word 2007 OOXML classes  all of which start with CL_DOCX*.
    Basically what we are trying to do is take a DOCX files (File 1 & File 2) saved by MS WORD 2007 application and replace the header of File 1 with the header from File 2.
    The basic functionality described above is working fine. However the same is not working when the header from File 2 has an IMAGE embedded in it.
    We found several  word 2007 OOXML classes  in the system (all of which start with CL_DOCX*), but couldn't find usage for these classes anywhere in the system or SDN or OSS Notes etc.,
    Just wondering whether anyone used these classes in their development environment and whether they can share this information here?
    Any help in this regard is highly appreciated.
    thanks,
    -Sreenath

    Which NetWeaver release are you using? The whole OOXML seems to be evolving within EhPs.
    You'll find examples how to use the framework in the Unit Tests of class CL_DOCX_FORM - so have a look at those classes. For me those test code runs fine.
    Best Regards,
    Tobias

  • How to use classes in Actions tab

    Hello guys!
    I'm just a beginner so i'm sorry for my stupid question.I'm developing a game in which movie clips in our case people have their own schedule.I have multiple screens and so i want to be able to set their locations and make them invisible on other screens(rooms)they're not currently at.The trouble is i can't use variables from Actions in my class,neither can i use classes in my Actions.Can anyone tell me how to export classes into Actions code?
    Here is my code:
    var currentlocation;
    var currentscreen;
    if (person.currentlocation!==currentscreen){
    person.visible=false;
    btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
    function fl_MouseClickHandler(event:MouseEvent):void
              currentscreen = "classroom";
              classroom.visible = true;
              playroom.visible = false;
    btn_2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);
    function fl_MouseClickHandler_2(event:MouseEvent):void
              currentroom = "playroom";
              classroom.visible = false;
              playroom.visible = true;

    Your problem/question is not clear to me.  If you are getting errors you should include the error messages in your posting.
    Could the problem arise from using a variable that is not defined?
    currentroom = "playroom";
    I do not see currentroom defined as a variable anywhere.  There is a currentscene variable though.

  • How to use class for Translate..codepage/numer format

    In the Unicode context, TRANSLATE... CODEPAGE/NUMBER FORMAT is not allowed.

    this is the class to be used for  Translate…Codepage/number format.statement
    Unicode Error : In the Unicode context, TRANSLATE... CODEPAGE/NUMBER   FORMAT is not allowed.
    Before Unicode
      TRANSLATE T143T-TBTXT FROM CODE PAGE '1100' TO CODE PAGE '1105'.
    After Unicode
       Use class for Translate codepage to codepage.
         Data : g_codepage LIKE tcp0c-charco VALUE '1100'.
    CONSTANTS: c_unicodecp(4) VALUE '1105'.
    PERFORM translate_codepage USING g_codepage
                                     c_unicodecp
                               CHANGING T143T.
    FORM translate_codepage  USING    P_G_CODEPAGE
                                      P_C_UNICODECP
                             CHANGING P_T143T.
      DATA: converter  TYPE REF TO cl_abap_conv_obj.
      DATA: l_out      TYPE string.
      DATA: l_fromcode TYPE cpcodepage.
      DATA: l_tocode   TYPE cpcodepage.
      l_fromcode = P_G_CODEPAGE.
      l_tocode = P_C_UNICODECP.
      CREATE OBJECT converter
        EXPORTING
          incode  = l_fromcode
          miss     = '.'
          broken   = '.'
          use_f1   = 'X'
          outcode  = l_tocode
        EXCEPTIONS
          invalid_codepage = 1
          internal_error   = 2.
      IF sy-subrc <> 0.
        CASE sy-subrc.
          WHEN 1.
            MESSAGE ID 'FES' TYPE 'E' NUMBER '024' RAISING unknown_error.
          WHEN 2.
            MESSAGE ID 'FES' TYPE 'E' NUMBER '024' RAISING unknown_error.
        ENDCASE.
      ENDIF.
      CALL METHOD converter->convert
        EXPORTING
          inbuff         = P_T143T
          inbufflg       = 0
          outbufflg      = 0
        IMPORTING
          outbuff        = l_out
        EXCEPTIONS
          internal_error = 1
          OTHERS         = 2.
      IF sy-subrc <> 0.
        CASE sy-subrc.
          WHEN 1.
            MESSAGE ID 'FES' TYPE 'E' NUMBER '024' RAISING unknown_error.
          WHEN 2.
            MESSAGE ID 'FES' TYPE 'E' NUMBER '024' RAISING unknown_error.
        ENDCASE.
      ENDIF.
      P_T143T = l_out.
    ENDFORM.                    " translate_codepage

  • How to use .class files from jsp

    hi i want to use .class files in my jsp program can any one help me

    so if you are using pacakges here is normal example...
    say you .java code is something like...
    package com.util;
    public Class BeanUtility{
    }place the .class file at WEB-INF/classes/com/util folder if those folders are missing create it and place the .class file there. or pacakage it as a jar file & put it into WEB-INF/lib folder
    Now in jsp you can either use jsp:Usebean tag or use normal scriplets to create an instance of the nessary class...
    here is an example for you
    <%@ page language="java" import="com.util.BeanUtility" %>
    <%
    BeanUtility bn = new BeanUtility();
    %>however,i'd suggest you to make use of JSTL / Inbuilt tag libraries /MVC 2.0 approach for better maintainance & readablity.
    Hope this might help
    REGARDS,
    RaHuL

  • How to Use NDS Tool and create a very simple application

    Hi All,
      Today i have Installed NDS on my machine,but i dont know
    how to use it,is there any guide inside NDS which gives me step by step procedure to create a simple application.
    Can any link help me know about this.version of NDS is 2.0.9.Is this latest one?
    I am pretty confused about NDS and PDK,if NDS can be used to develop java apllications ,then whats the need of PDK at all?
    Thanks in Advance
    Rani A

    Hi Rani,
      The Portal Development Kit (<b>PDK</b>) provides documentation and examples with source code to demonstrate how to develop portal applications and portal content for the SAP NetWeaver Portal using the <b>SAP NetWeaver Developer Studio</b>.
    PDK includes coding examples on the following topics:
    *Creating Portal Components and Portal Services,Portal Profiles,Resources,Internationalization,Portal Beans,Page Builder,EPCF,Application Integrator,Connector Framework,Portal Navigation,Object Based Navigation,Transformation Service,User Management etc
    PDK is for deployment for portal application, has very good documentation of portal development, contains sample application, Java Docs for all the apis for portal and KM and plugins for eclipse(which you don't need if you are using NWDS). It is basically a nice help for developer along with an iviews for uploading par and testing them.
    In EP 6.0 it is just business package that you import to your portal. This will then give a "java development" role in portal which can be assigned to users. The role will then create a tab called "Java Development" in the top navigation and click on it you can see all the contents underneath.
    If u want to see the application on which an iview is based on import that par file into NWDS.
    Regards,
    Pooja.

  • How to use Synchronized method when creating our own controls

    I don't know how to use the synchronized method when creating our own activex like controls to speed up the application.

    [url http://java.sun.com/docs/books/tutorial/essential/threads/multithreaded.html] here you go 

  • How to use ora:processXSLT to create HTML with BR tags included?

    I am using a .xsl to create HTML for use as part of a notification process. The issue is that if in the .xsl I include the
    tag, when the transform engine runs to make the HTML it creates <br> tags with out the maching </br> tags. (in doing some reading this seems to be a feature of most XSLT engines) But the result is invalid XML, so when I attempt to assign the output to a variable the process faults and I get the following error:
    XPath expression failed to execute.
    Error while processing xpath expression, the expression is "ora:processXSLT("XML_PURCHASE_ORDER_to_HTML.xsl", bpws:getVariableData("inputVariable", "payload", "/ns1:XML_PURCHASE_ORDER"))", the reason is The XML data is invalid.
    The XML data is invalid; the reason is "Error on line 100 of document : The element type "br" must be terminated by the matching end-tag "
    ". Nested exception: The element type "br" must be terminated by the matching end-tag "
    Message was edited by:
    mlutze
    Message was edited by:
    mlutze
    Message was edited by:
    mlutze

    You can probably set the output format in the stylesheet, like:
    <xsl:output method="txt" indent="no" omit-xml-declaration="yes" />
    if you really don't want to use xhtml. The result might have to be wraped in a cdata block in the bpel flow?
    cheers
    /Stig

  • How to use class in JSP file?

    Hello All,
    I am new to Jsp.
    In Jsp file,I used class of myself.
    Why,the Constractor seems not working?
    Thanks in advance.

    Hi,
    You can import the class in a jsp file.
    Use <% page import = "">
    and call that class.
    If u want to import a funtion in your class, then u can insert that into scriplets like <%! ..%>
    Hope u got that!
    Artz

Maybe you are looking for

  • How do I move an App from the cloud to my iPad?

    I downloaded an App (Houston Chronicle for iPad) and somehow I placed it on the Cloud instead of on my iPad. How do I move the App to my iPad?

  • ITunes in external hard drive

    My home laptop hard drive has crashed but I had all my iTunes (3500 songs) on an external hard drive. Now I have connected my external hard drive to my work desktop PC with Windows. I have downloaded iTunes software onto the new computer and I can ma

  • Why is Encore CS4 crashing......

    I often get the message: "Adobe has detected that the application AE has unexpectedly quit." My preview video runs slow and jumpy. My project is Origional 32.8GB and Resulting 20.8GB. It is full of transitions, titles, and a few effects, most to brig

  • Scope backingbean

    I have 2 backingbean: The faces-config.xml look like : <faces-config> <managed-bean> <managed-bean-name>Ca</managed-bean-name> <managed-bean-class>com.backbase.bjs.example.ClienteActivo</managed-bean-class> <managed-bean-scope>session</managed-bean-s

  • Please help! Quick.

    Hello, I created a website on iWeb a few months ago on my old computer (an eMac), since then I have upgraded to a brand new computer, and transferred my files to the new Mac. But when I open iWeb on my new computer, my old website is not there and I