Adding an Icon to a JButton Component - Not working

Hi all,
Please help me by saying, why the below gevon SSCE doesnt work.
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
public class CreateWindow {
    public CreateWindow(String module, String id){
         if(module.equals("mail")){
              JPanel mail = new JPanel(null);
              mail.setPreferredSize(new Dimension(500, 350));
              //Color colr = new Color(222, 236, 255);
              mail.setBackground(Color.WHITE);
              JLabel file = new JLabel("File Name:");
              file.setBounds(18,25,75,50);
              // Retrieve the icon
             Icon icon = new ImageIcon("ei0021-48.gif");
             // Create an action with an icon
             Action action = new AbstractAction("Button Label", icon) {
                 // This method is called when the button is pressed
                 public void actionPerformed(ActionEvent evt) {
                     // Perform action
             // Create the button; the icon will appear to the left of the label
             JButton button = new JButton(action);
              mail.add(button);
              buildGUI(mail,500, 350);
    public void buildGUI(JPanel panel, int width, int height)
        JFrame.setDefaultLookAndFeelDecorated(true);
        UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.LIGHT_GRAY));
        JFrame f = new JFrame("Propri�t�s:");
        f.setIconImage(new ImageIcon("save.gif").getImage());//need an image file with black background
        changeButtonColor(f.getComponents());
        f.getContentPane().setBackground(Color.WHITE);
        f.getContentPane().add(panel);
        f.getRootPane().setBorder(BorderFactory.createLineBorder(Color.PINK,2));
        f.setSize(width,height);
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        f.setVisible(true);
      public void changeButtonColor(Component[] comps)
        for(int x = 0, y = comps.length; x < y; x++)
          if(comps[x] instanceof AbstractButton)
            ((AbstractButton)comps[x]).setBackground(Color.LIGHT_GRAY);
            ((AbstractButton)comps[x]).setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
          else if (comps[x] instanceof Container)
            changeButtonColor(((Container)comps[x]).getComponents());
}I call the above given class constructor as given
public class Test {
     public static void main(String args[]){
          CreateWindow cw = new CreateWindow("mail","Test.doc");
}Rony

RonyFederer wrote:
I have the images and class files inside
F:\Testing3\Application\src\booodrive
Do you have the class files or java files here?
You should put the gif where the .class files are located, and use getResource as Encephalopathic wrote, or:
Icon icon = new ImageIcon(ClassLoader.getSystemResource("ei0021-48.gif"));
When I did as you said using System.out.println(new File("ei0021-48.gif").getAbsolutePath());, I got the following output.
F:\Testing3\Application\ei0021-48.gif
That's the current running directory.

Similar Messages

  • Component not working

    JDEV 11.1.1.2.0 with adf 11g
    i have thow the exception in button commandToolbarButton of actionListener, after throwing exception , button commandToolbarButton working is stop , how to resolve , please help me,
    regards,

    Hello all,
    I am facing an issue with CommandToolbarButton. On Click of the button, I am not able to call the actionListener backingbean method. I have default PartialSubmit true and immediate to false. It does not throw any error but just does not call the method. Here is the code :
    <af:commandToolbarButton id="commandButton1"
    actionListener="#{backingBeanScope.xxxBean.addRecord}"
    icon="/add.gif"
    shortDesc="#{ViewControllerBundle.ADD}"
    partialTriggers="t5" immediate="false"/>
    However, with similar code on another fragment, I am able to call the action listener.
    Can anyone let me know what the issue could be with the component not working on this page ?
    Thanks,
    Victor

  • Flash player 10.3.1.8.34 (lastest verison)icon on my desktop ,does not work ?

    .I>m using windows7 OS IE9 downloaded and installed fifty times and it always say download and installation was sucessful ,that I"m now using flashplayer 10.5 ect. there is the flashplayer icon sitting right on my desktop .from control panel in programs there is is adobe flash player in the list. every time i click to view a video,says to view this i need to download flash player over and over, I"ve read all the other post.tried all the answers ,been to all support sitesmore than 10 times each I"ve been up all night again it"s now morning  i"m still lost.all help will be appreciated...................................                penny

    Yes all that u sugested i followed from the help and support at adobe.Now i downloaded flashplayer beta 11 and it"s working perfectly .I"m at peace for the moment.In my profile i "ve given my PC model and the whole works on my system.for the record I"m using windows7,IE 9,64bit shockwave is enabled and active xfiltering was disabled it just would not work..
                            thank u very much
    From: ʇɐb ɹəuəllıʍ <[email protected]>
    >To: penny torrence <[email protected]>
    >Sent: Monday, July 25, 2011 8:57 PM
    >Subject: Re: flash player 10.3.1.8.34 (lastest verison)icon on my desktop ,does not work ?
    >
    >
    >1. There is no Flash Player 10.5; the currently available version is 10.3
    >2. What Internet Explorer version are you using: 32-bit or 64-bit?
    >3. What Windows version are you using: 32-bit or 64-bit?
    >4. Have you checked the add-ons on IE9 (Shockwave Flash Object); is it enabled?
    >5. Have you checked ActiveX Filtering on IE9; is it enabled?  (It needs to be disabled.)
    >

  • TS1424 I was buying songs on my itune account, and now my itunes icon on my computer will not work at all, I do not know how to sign back into

    I was buying songs on my Itunes account and I signed-out and now my Itunes icon on my desktop will not work at all.  How do you access your account

    http://support.apple.com/kb/TS1538
    Try rebooting it and connect. Make sure you're connected directly to a USB port using the Apple USB cable.

  • Mac OS X v 10.5.8.    My "Weather" on the dashboard no long works.  I have deleted it and added it anew and it still does not work. How can I get it back?

    My "Weather" on the dashboard no long works.  I have deleted it and added it anew and it still does not work. How can I get it back?

    You must get 10.6 if they still have it, install it & update to 10.6.8 so you have the App Store to buy & download the huge 10.8 Installer.(10.9/Mavericks is the only download avaiable now without specially calling Apple).
    Snow Leopard/10.6.x Requirements...
    General requirements
       * Mac computer with an Intel processor
        * 1GB of memory (I say 4GB at least, more if you can afford it)
        * 5GB of available disk space (I say 30GB at least)
        * DVD drive for installation
        * Some features require a compatible Internet service provider; fees may apply.
        * Some features require Apple’s MobileMe service; fees and terms apply.
    Which apps work with Mac OS X 10.6?...
    http://snowleopard.wikidot.com/
    It's been pulled from the online store & Apple Stores, so you have to call Apple to buy it, last I heard.
    Buy Snow Leopard > http://store.apple.com/us/product/MC573/mac-os-x-106-snow-leopard
    Call Apple Sales...in the US: 1-800-MY-APPLE. Or Support... 1-800-275-2273
    Other countries...
    http://support.apple.com/kb/HE57
    It looks like they might still have it...
    http://store.apple.com/us/product/MC573Z/A?fnode=MTY1NDAzOA

  • The itunes ogg drop X component not working

    Hi there,
    I installed the itunes ogg drop X component not working from Ogg Drop X 1.0b5 and rebooted.
    I still cant play ogg streams. they play fine in a VLC player so I know they work.
    any body get the Ogg Drop X 1.0b5 itunes component working. How do I get it goin'?
    Cheers

    no response.

  • HT4623 my iphon 4s got problem when i was updating it and screen become black and there is a usb & itone icon on it it dose not work any more ..any feedback about this guys?

    my iphon 4s got problem when i was updating it and screen become black and there is a usb & itone icon on it it dose not work any more ..any feedback about this guys?

    Connect it to iTunes and restore it.

  • The Gmail icon for attaching files does not work in Firefox

    I have tried the config change for network.http.spdy.enabled to false, and quite a few other suggestions for this problem, some from years ago.
    Only the attach file icon is affected. Dragging files into gmail works to attach them, just the icon is not working.
    Very perplexing.

    Try allowing pop up windows
    Open Menu
    Options
    Content (on the top)
    Click Exceptions...
    Type mail.google.com in address of website area
    Click Allow
    Try to open attachment window now.
    Restart FireFox and try adding attachment again.

  • Adding multiple locales to TwitterTrends mobile sample - not working

    Hi All,
    I have been having trouble adding support for muliple locales in my application so I desided to try it out with TwitterTrends sample application. Should be easy, but not working for me...
    What I did:
    1. Add locale folder under assets with an en_US sub folder
              src/assets/locale/en_US
    2. Create a properties file for en_US and save to src/assets/locale/en_US
         src/assets/locale/en_US/twittertrends.properties
    3. Add a single resource key for the home view in 'twittertrends.properties'
         views.home.title=Twitter Trends
    4. Update the TwitterTrendsHome.mxml to use fetch the title from the properties file
         title="{resourceManager.getString( 'twittertrends', 'views.home.title' )}"
    5. Add the locale folder to the applications source path, I did this by modifying the additional compilter args for Flash Builder:
         -locale en_US -source-path=assets/locale/{locale}
    Result:
    No title is displayed..
    I am not sure what I did wrong. Any help is much appreciated.
    Has anyone else seen/not seen this issue?
    Cheers,
    Greg

    Try adding
    <fx:Metadata>
        [ResourceBundle("twittertrends")
    </fx:Metadata>
    The problem is that the compiler isn't smart enough to tell that you're using the 'twittertrends' resource bundle unless you tell it so via [ResourceBundle] metadata. It doesn't try to analyze the ActionScript code inside of databinding expressions to determine what parameters you are passing to ResourceManager functions, etc.
    If instead of databinding you use the @Resource() compiler directive, as in
    title="@Resource('twittertrends', 'views.home.title')"
    then it should be able to figure this out without the [ResourceBundle] metadata. But this way of doing it doesn't support switching the locale at runtime.
    Gordon Smith
    Adobe Flex SDK Team

  • SSRS 2008 Work order Report , when added item descriotion , somehow costgroup id is not working , donot know why, ( need help)

    SSRS 2008 Production orders created report, when I added item description some how cost group id is not working ,
    my costgroup id did not break into labor , only Mat Cost showed in the total,
    my query is as below,  did I link the wrong field,   I want to show Labor total also
    can some one suggest what I did wrong .
    any advise will be great
    SELECT        PRODTABLE.PRODID, PRODCALCTRANS.COSTGROUPID, PRODTABLE.QTYCALC, PRODTABLE.PRODSTATUS, PRODCALCTRANS.COSTAMOUNT,
                             PRODCALCTRANS.COSTMARKUP, PRODCALCTRANS.REALCOSTAMOUNT, PRODCALCTRANS.CALCTYPE, PRODTABLE.DATAAREAID, PRODCALCTRANS.KEY3,
                             PRODCALCTRANS.CONSUMPVARIABLE, PRODCALCTRANS.REALCONSUMP, PRODTABLE.ITEMID, PRODTABLE.SCHEDDATE, PRODTABLE.FINISHEDDATE,
                             PRODCALCTRANS.KEY1, PRODCALCTRANS.TRANSDATE, PRODCALCTRANS.QTY, PRODCALCTRANS.KEY2, PRODCALCTRANS.COLLECTREFLEVEL,
                             PRODCALCTRANS.LINENUM, INVENTTABLE.ITEMNAME, INVENTTABLE.ITEMID AS Expr1, PRODTABLE.INVENTTRANSID
    FROM            PRODTABLE INNER JOIN
                             PRODCALCTRANS ON PRODTABLE.PRODID = PRODCALCTRANS.PRODID AND PRODTABLE.DATAAREAID = PRODCALCTRANS.DATAAREAID INNER
    JOIN
                             INVENTTABLE ON PRODCALCTRANS.DATAAREAID = INVENTTABLE.DATAAREAID AND PRODCALCTRANS.KEY1 = INVENTTABLE.ITEMID
    WHERE        (PRODTABLE.PRODSTATUS = 7) AND (PRODTABLE.DATAAREAID = N'AR1') AND (PRODTABLE.ITEMID = @itemid) AND
                             (PRODTABLE.FINISHEDDATE >= @Paramfromdate) AND (PRODTABLE.FINISHEDDATE <= @Paramtodate) AND (PRODCALCTRANS.COLLECTREFLEVEL
    = 1) AND
                             (PRODCALCTRANS.CALCTYPE >= 0)

    Hi Bitia,
    As per my understanding, after you add Item field to the report, it does not calculate total of matl group, right? If that is the case, please refer to the following steps to troubleshoot the problem:
    Modify the dataset used to retrieve data, delete the fields will not be used in the report.
    Run the query in SQL Server Management Studio (SSMS) to make sure that there is data for matl cost group.
    Make sure that row group and totals are correctly added.
    In addition, do you want to add Finished date to page header? If that is the case, we can use ReportItem to achieve the goal. Please refer to the following steps:
    In design surface, right-click the report and click Insert, then click Page Header.
    Drag Text Box from Toolbox to page header.
    Right-click inside of Text Box, then click Expression.
    In the expression text box, type the code like below:
    =ReportItems!FinishedDate.Value
    If the problem remain unresolved, please provide the screenshot of the report in design view, the following screenshot is for your reference:
    Reference:
    ReportItems Collection References
    Adding Grouping and Totals
    Thanks,
    Wendy Fu

  • Adding contacts to my new 8900 is not working.

    adding contacts from oultlook and /or outlook express to my new 8900 is not working. i tried everything from removing and re-installing the desktop manager to removing the battery of the device. nothing seems to be working.

    Ah, very helpful when we have the complete information.
    Desktop Manager 4.7 is not compatible with Outlook 2000, so that won't work. You will need to use DM version 4.2, Service Pack 2; or upgrade your Outlook to 2003 or better.
    For Express, it should work with Outlook Express 6. Check your advanced sync settings configuration and make sure you have it set to two-way sync and to notify you. 
    Desktop Manager 4.7:
    The following organizers are supported for use with Intellisync:
    IBM Lotus Notes 6, 6.5, 7, 8
    Microsoft Outlook 2002, 2003, 2007
    Microsoft Outlook Express 6, Microsoft Windows Contacts (Vista Address Book)
    Novell GroupWise 6.5, 7
    Yahoo!®
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Added field to dynamic selection screen does not work in FBL5N

    hi,
    we have added KNA1-KATR5 to the selection screen of FBL5N by using logical database DDF using "view CUS" but it does not work.
    Our system is 6.0
    is there any OSS note or program that we should add?
    many thx.

    Refer This:
    Additional field selections in FB03

  • I have lost my camera icone and my camera is not working how to resolve the same.

    Hi Team,
    Camera on 3gs is not working its d't show the display and i have lost its icon on task manager kindly provide me detail hw can i resolve the same.
    Also one of my iphone in which i have faced charging issue phone is not charged kindly help me regarding the same.

    settings->general->reset->reset home screen layout
    should bring it back

  • Searchspec on Siebel Integration Component not working

    Hi All,
    Has anyone successfully applied the user property 'searchspec' on a Integration Component?
    I have tested but it's not working for me. I have seen that this user property exist on some of the standard vanilla ICs.
    Regards,
    Hakan

    I agree, we have not been able to get it to work. What you're supposed to be able to so is pass the SearchSpec as a parameter through the web service so the web service will apply that spec to the IO when querying, but that also does not work (though it's supposed to). I have an open ticket with Oracle and they are identifying the issue as we speak.

  • Embeded Flash component not working

    I have createdf a Flash movie using the Drag & Drop
    Learning Interactions Component using Flash MX 2004. The
    interaction works fine as standalone Flash movie but when embedded
    in an Adobe Presenter presentation, the drag works ok but it will
    not drop the object. I have had the Breeze control the Flash movie
    and also Breeze not control the movie.
    Any ideas?

    Hi Conrad!
    As you have no doubt already realized, using the Learning
    Interaction templates that are available in Flash MX / MX2004 and 8
    will not work at all in Presenter content.
    The coding methods conflict while playing back within the
    Breeze environment and I
    think it has to do with the _dropTarget property as part of
    the interaction's codebase. The _dropTarget method is NOT supported
    in Breeze, but the hitTest() method IS!
    I have written a few drag and drop exercises that do work
    within Breeze content, and you have to use the hitTest() method to
    accomplish it.
    As you already have discovered, the bottom line is that the
    learning components were intended to be "stand alone" objects that
    could be incorporated into a web page (or even a CD as these
    objects are nothing more than swf files). Aside from the fact that
    the prebuilt/preconfigured learning objects in flash don't always
    work in Breeze, in my mind, the bigger question here is the ability
    (or more accurately) the inability to connect these SCO's to an LMS
    for tracking. As stand alone objects, they're actually pretty
    handy...but not in Breeze.
    I realize this doesn't help much with what you're trying to
    do, but from my perspective, you're better off creating your own
    drag n' drops.
    I've got a bunch of examples to share if you'd like to take a
    look...just send me a PM or email if you're interested.
    Rob
    [email protected]

Maybe you are looking for

  • Releasing Transport Request Error.

    Hi all, I have created the Query Objects under a Transport Request in Development System and has to be transported to the QA system. One thing i have observed is, when u create a Transport request for an Object. Two Transport Requests will be created

  • Missing characteristics in report

    Hi, We recently upgraded our system from 3.5 to 7.0 and found out that one characteristic 0vtype is missing in the report after the upgrade but the data content is the same. How do I  get this missing characteristic to display as it is before the upg

  • Browser Questions: Getting to home page and reordering bookmarks?

    Have two quick questions about the Playbook Browser (which is awesome, by the way!) 1. How do you get back to your configured home page once you've been surfing around? I see no "Home" button anywhere. Is there a gesture or something that will take y

  • Problem with deleting a file..FILE I/O

    Hi, I have been trying to delete a file using File class's delete method. In my application, I am creating files using File.write method dynamically.after some point I would like to delete the same file which can be captured by the user's action. I a

  • Canon HV20. Anyone using one? Any problems with iMovie HD?

    So as a follow up to my other post about the Sony, has anyone been using Canon's HV20 with iMovie hd? If I can't get the older Sony to run with iMovie, I'd probably check this out over the Sony HD model, given all the reviews I've read. I really woul