Desperately seeking help for displaying image on button

i wrote the following method to create and display a button with an icon, doesn't work and i cannot figure out what the problem might be and how to fix it, please help me...
clo :))
public static void addButton(Container c, String title,
ActionListener listener)
JButton button = new JButton(title);
button.setBorder(null);
button.setFocusPainted(false);
button.setBorderPainted(false);
button.setContentAreaFilled(false);
ImageIcon icon = new ImageIcon("anImage.jpg");
button.setIcon(icon);
c.add(button);
button.addActionListener(listener);
the parameter c is of JPanel type and gets added to a JFrame object,
the source compiles and runs but i see no image on my button, sigh :((!
PS(the image file is placed in the same dir as the source file).

Why buttons and labels might not show up the icon?
Either your image is not in the classpath and you are trying to load it as a resource: see
http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html
or you are running the java machine from a different directory that you expect it does.
or the file doesn't exist.
To prove that the system cannot load the image use the example in the above link and the url will be null.
URL iconURL = ClassLoader.getSystemResource("anImage.jpg");

Similar Messages

  • Help with displaying image received from socket on Canvas

    Dear programmers
    I know that I'm pestering you lot for a lot of help but I just got one tiny problem which I just can't get over.
    I'm developing a remote desktop application which uses an applet as it's client and I need help in displaying the image.
    When a connection is made to the server, it continuously takes screenshots, converts them to jpg and then send them to the client applet via socket communication. I've got the the server doing this in a for(;;) loop and I've tested the communication and all seems to be working fine. However the applet is causing some issues such as displaying "loading applet" until I stop the server and then the 1st screenshot is displayed. Is there a way to modify the following code so that it displays the current image onto a canvas while the next image is being downloaded and then replace the original image with the one which has just been downloaded. All this needs to be done with as little flicker as possible.
    for(;;)
        filename = dis.readUTF();
        fileSize = dis.readInt();
        fileInBuffer = new byte[fileSize];
        dis.readFully(fileInBuffer, 0, fileSize-1);
        //Create an image from the byte array
        img = Toolkit.getDefaultToolkit().createImage(fileInBuffer);
        //Create a MyCanvas object and add the canvas to the applet
        canvas = new IRDPCanvas(img, this);
        canvas.addMouseListener(this);
        canvas.addKeyListener(this);
        add(canvas);
    }

    Anyone?

  • Af:commandImageLink not processing the aboulite path for displaying image

    All,
    We are required to display an image in the UI. The image is not stored in the deployed ear file. It is stored in the "*<DOMAIN_HOME>\Inventory\images*".
    Where DOMAIN_HOME=D:\JUPITER_CORONA\system11.1.1.3.37.56.60\DefaultDomain\inventory
    I would process an image absolute path in the af:commandImageLink tag as follows,
    *<af:commandImageLink "icon=file://D:/JUPITER_CORONA/system11.1.1.3.37.56.60/DefaultDomain/inventory/images/equipment.png" text"equipment" shotdesc="icon" />*
    The problem is that the above tag is not processing the above mentioned absolute path and displaying text "icon" instead of actual icon image. As per the ADF documentation the tag processes absolute path as well.
    Can someone suggest as to where I am going missing.
    regards,
    Chandra

    I was not able to get what you want very well, the situation is a little bit un-usual,
    but for solution I suggest the below way.
    write a servlet/JSP that return the image (it is like copying the file, read the image from absolute path and send it to the OUTPUTSTREAM of the response aslo remember the MIME and the write filter for the jsp/servlet that end with .jpg or any extension for the image.)
    then in the jsf page write the below code.
    <af:commandImageLink icon="/jspOrservlerpath/servlet/filename.jpg" text"equipment" shotdesc="icon" />
    your servlet (get the filename.jpg and then find the file and return it)
    this solution is very common for cases that the file is not available physically such as when you want to read it from another place(your case) or database.
    I hope this help you.
    I can send you the source for the servlet/jsp if you want.

  • Alternative method for displaying images blobs stored in DB

    I am trying to use an Application Process as a means to displaying images stored in BLOB columns in my table. And it works except for one problem. The code for my on-demand Application Process is below (the name of the application process is OUTPUT_IMAGE):
    DECLARE
    l_mime VARCHAR2(255);
    l_length NUMBER;
    l_file_name VARCHAR2(2000);
    lob_loc BLOB;
    BEGIN
    SELECT photo_mime_type,
    photo_blob,
    photo_filename,
    dbms_lob.getlength(photo_blob)
    INTO l_mime,
    lob_loc,
    l_file_name,
    l_length
    FROM persons
    WHERE id = <b>260</b>;
    owa_util.mime_header(nvl(l_mime,'application/octet'), FALSE);
    htp.p('Content-length: ' || l_length);
    htp.p('Content-Disposition: filename="' || l_file_name || '"');
    owa_util.http_header_close;
    wpg_docload.download_file(lob_loc);
    END;
    I can then create HTML like:
    &lt;img src="f?p=[my_app_id]:0:[the_session_id]:APPLICATION_PROCESS=OUTPUT_IMAGE"&gt;
    Which works nicely.
    The question/problem is: How can I pass the ID of the record (whose BLOB I want to display) to the Application Process? (In the code above you'll see the value of <b>260</b> is currently hard coded). I thought about tacking on something like "&my_id=xxx' to the end of the URL but doing so prevents the Application Process from even running.<BR/><BR/>
    All comments/suggestions much appreciated,<BR/><BR/>
    Thanks,
    <BR/>
    Andy

    Andrew,
    The URL for an Application Process uses the standard f?p syntax.
    Try passing your value like this:
    < img src="f?p=[my_app_id]:0:[the_session_id]:APPLICATION_PROCESS=OUTPUT_IMAGE:NO::MY_ID:[the value to send]"> You would need to have an item called MY_ID.
    Your query could then refer to it as
    WHERE id = :MY_ID;
    Doug

  • Help with displaying images (gif, jpeg...) within a JFrame (or similar)

    Hi all,
    i'm new to the forum and i'll be granted if you kind gentlemen/women could use some advices for my gui home application.
    My purpose is to display a static image in a container (i'd prefer to use javax.swing objects, but if you think that java.awt is more suitable for my app, please feel free to tell me about...). I used a modified code from one of the Java Tutorial's examples, tht actually is an applet and displays images as it is using the paint() method. I just can't realize how to set the GraphicContext in a JFrame or a JPanel to contain the image to display, without using applets. Following part of the code I use (a JButton will fire JApplet start, JApplet is another class file called Apple.java):
    class DMToolz extends JFrame {
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         private JButton jButton = null;
         private JComboBox jComboBox = null;
         private JMenuItem jMenuItem = null;
         private JMenuBar jJMenuBar = null;
         private JMenu jMenu = null;
         private JMenu jMenu1 = null;
         public int w=10, h=10;
         public String filename;
          * @throws HeadlessException
         public DMToolz() throws HeadlessException {
              // TODO Auto-generated constructor stub
              super();
              initialize();
         public DMToolz(String arg0) throws HeadlessException {
              super(arg0);
              // TODO Auto-generated constructor stub
              initialize();
          * This method initializes jButton
          * @return javax.swing.JButton
         private JButton getJButton() {
              if (jButton == null) {
                   jButton = new JButton();
                   jButton.setBounds(new Rectangle(723, 505, 103, 38));
                   jButton.setText("UrcaMado'");
                   jButton.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
    /**************SCRIVERE QUI IL NOME DEL FILE CON L'IMMAGINE DA CARICARE*******************/
                             filename = "reference table player2.gif";
                           java.net.URL imgURL = DMToolz.class.getResource("images/"+filename);
                           BufferedImage img = null;
                           try {
                                img =  ImageIO.read(imgURL);
                               w = img.getWidth();
                               h = img.getHeight();
                               System.out.println("*DM* Immagine letta - W:"+w+" H:"+h);
                            } catch (Exception ex) {System.out.println("*DM* Immagine non letta");}
                           JApplet a = new Apple();
                           a.setName(filename);
                           JFrame f = new JFrame ("UrcaBBestia!");
                           f.addWindowListener(new WindowAdapter() {
                               public void windowClosing(WindowEvent e) {System.exit(0);}
                           f.getContentPane().add(a);
                           f.setPreferredSize( new Dimension(w,h+30) );//30 � (circa) l'altezza della barra del titolo del frame
                               f.pack();
                             f.setVisible(true);                      
              return jButton;
    public class Apple extends JApplet {
         private static final long serialVersionUID = 1L;
        final static Color bg = Color.white;
        final static Color fg = Color.black;
        final static Color red = Color.red;
        final static Color white = Color.white;
        public void init() {
            //Initialize drawing colors
            setBackground(bg);
            setForeground(fg);
        public void paint(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            try {
                 String filename = this.getName(); //uso il nome dell'applet come riferimento al nome del file da caricare
                 java.net.URL imgURL = DMToolz.class.getResource("images/"+filename);
                 BufferedImage img =  ImageIO.read(imgURL);
                 if (img.equals(null)) {System.out.println("IMG null!");System.exit(0);}
                System.out.println("IMG letta");
                int w = img.getWidth();
                int h = img.getHeight();
                resize(w,h);
                g2.drawImage(img,
                            0,0,Color.LIGHT_GRAY,
                            null);// no ImageObserver
             } catch (Exception ex) {ex.printStackTrace();
                                          System.out.println("Immagine non letta.");System.exit(0);}
    }//end classPlease never mind about some italian text, used as reminder....
    Thanks in advance.

    Read the Swing tutorial on "How to Use Labels" or "How to Use Icons" for working examples:
    http://java.sun.com/docs/books/tutorial/uiswing/TOC.html
    By the way you should never override the paint() method. Custom painting (not required in this case) is done by overriding the paintComponent(...) method in Swing. Overriding paint() is an old AWT trick.

  • Problem for displaying image in jsp

    I like to retrieve and display image from database in jsp file. Now, image has been retrieved and store in session. But it cannot be displayed in jsp. Who can help me? Thanks a lot!
    Codes like below:
    <%
    byte[] b = (byte[])session.getAttribute("sessionName");
    System.out.println(b.length); //the length can be printed at console successfully
    if(b != null) {
    response.setContentType("image/*");
    OutputStream toClient=response.getOutputStream();
    toClient.write(b);
    toClient.flush();
    toClient.close();
    %>

    JSP is designed to return text/html documents.
    As such it automatically calls getWriter() to return a character stream. (places it in the implicit variable "out"
    Seeing as you want to return bytes, instead of character data, the JSP technology is not applicable
    Calling getOutputStream after getWriter has been called results in an IllegalStateException
    So calling getOutputStream in a JSP will ALWAYS throw an exception.
    Cheers,
    evnafets

  • How can I restore the background color Firefox 13 used for displaying images?

    I preferred the darker background color introduced in Firefox 13 for when images were displayed standalone, as opposed to the glaring white. How can I restore that behavior?

    That should still happen.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    You can also check for a userChrome.css file with code to change the background color.
    The customization files userChrome.css (interface) and userContent.css (websites) are located in the chrome folder in the user profile folder.
    *http://kb.mozillazine.org/Editing_configuration

  • HELP FOR OPEN IE FROM BUTTON CLICK ?

    Hello All,
    i make a jframe i want to open internet explorer window for particuler site by button
    click any body tell me plz.
    Thanks ...
    Arif.

    See this Application below, use it in your application
    //to open an application during the run time use runtime
    //n no of applications can be opened during the run time
    import java.awt.*;
    import java.io.*;
    public class RT
    public static void main(String str[])
    try
    Runtime rt = Runtime.getRuntime();
    rt.exec("notepad"); //exit or execute
    // rt.exec("wordpad");
    rt.exec("c:/progra~1/netscape/communicator/PROGRAM/NETSCAPE.EXE");
    /* Process p = exec(perl xyz.pl);
    DataInputStream dis = new DataInputStream(p.getInputStream());
    System.out.println(dis.readLine()); */
    catch ( Exception e)
    e.printStackTrace();

  • Seeking Help with Album Image Issues in iPod Classic

    Hi folks -
    I have a new 160 iPod Classic and have two album image-related issues I'd appreciate some help with.
    In the case of several albums where I'd associated my own art with them in iTunes, the formatting appeared off in my iPod due to the vertical/horizontal proportions. So I corrected the images, replaced the images via iTunes, and re-synced. All of the old images were replaced - except for two. Is there any way to get my iPod to recognize the change to these two images, as it did for all the others?
    Secondly, my "The Allman Brothers Band Live at Fillmore East" album was appearing twice in both the Cover Flow and Album list. That was strange, except that after the latest sync it now appears six times! It's only in one place in iTunes, and not erroneously set as a compilation or anything. This is the only album displaying this behavior...
    Thanks for any suggestions or advice!
    Frank
    Message was edited by: frank3si

    Yes my e-mail address is [email protected] 
    Thank you for your kind attention to my problem. I am looking for one on one brief consultation with my laptop in Cincinnati. If not then I will compose a clear question with VI.
    These manuals are well known to me NI Visions Concepts ManualIMAQ Vision for LaVIEW User ManuelNI-IMAQ for USB Cameras My problem is moving to the next step of Create an array of USB imagePerform math on array Display results Sincerely,Tom Lohre cell 513-236-1704, [email protected] http://tomlohre.com/images/lafley.jpgAG Lafley, Chairman & CEO of Proctor & Gamble http://tomlohre.com/lafley.htm A.G. Lafley enjoyed hearing of Tom's painting robot and thought it played well to his new book: "The Game-Changer: How You Can Drive Revenue and Profit Growth With Innovation." http://tomlohre.com/newart.htm
    Tom Lohre artist/scientist
    Has a operating painting robot using RoboLab/RCX
    Developing a LabView/ NXT robot that analyzes an image for aesthetic quality.

  • Formula for displaying images

    Tried the documentation found at crystal reports support site with no luck, hopefully these forums can help.
    I have been searching for a way to use a conditional formula, or some preinstalled function to:
    1. display an image based on whether there is a table entry ( which is the filename)
    2. if nothing exists in the table entry, display an image from a fall back web URL.
    here is the snippet I am starting out with -
    if({IDCARD.IDPHOTO} = "") then
    'https://xx.xx.com/infodir/images/' & {USERTABLE.PHOTO}
    the CRXI object model is kind of new to me so im fairly sure this is simple, but looking for a kick in the pants into the right direction, or some testable/trusted solution.
    any assistance would be great.

    What you can try is:
    1. Insert default .jpg picture into your report
    2. Right-click the image and select Format Graphic> select Pictures tab> Graphic Location formula
    3. Insert your formula, but make sure that result of your formula is a string - full pass to .jpg file
    I have tested it right now and it works for my CRXIr2.

  • How to use boimage url for displaying images

    I am trying to test the Image URL feature in a Web Intelligence report.
    I have a few images loaded in the images folder on the installation server.
    I made the text of a cell: boimage://auditingBOBJLogo.png
    No images are showing up. When I am in view mode a box with an x shows.
    I am using the Web Client to edit the report and view it in InfoView.
    Any tips or best practices for getting this to work would be appreciated.
    Thanks

    Hi,
    Make sure that you have placed the image files in correct folder.
    And the cell formula is boimg://auditingBOBJLogo.png and not boimage://auditingBOBJLogo.png.
    Remember to set the display property of the cell to Image URL.
    Regards

  • Seeking help for a  report design

    How to create dynamic footnotes, if it's even possible, with Oracle
    Reports?
    A dynamic footnote would be one that appears on a page only if it is
    used on that page.
    For example:
    Regions: South East West North
    Widget A
    S: $1500.
    E: $100.
    Footnotes:
    S = South
    E = East
    ------------- (page break of group or bottom of page) --------
    Widget B
    S: $1500.
    W: $100.
    Widget C
    S: $1500.
    Widget D
    S: $15002.
    W: $100.
    Footnotes
    S= South
    W = West
    We only want the ones that are used on the page to appear on the footnote
    Any help will be appreciated,
    Thanks.

    Hallo Denis,
    I have a similar problem: Want to display some value from the database in a margin field. I created a user parameter v_Title_Crew and pressetted it in the format trigger of a formula field. Used srw.set_field_char (0, :v_Title_Crew) in the format trigger of the margin field to display the content of the variable. But unfortunately this does not work: It seems to me that the margins are prepared before the query is executed; the variable is not set. Before I simply connected the margin field to the variable in the property palette but this didn't work better. Any idea how to solve this problem?
    Thanks and regards - Ulrich

  • Need help for displaying key and description in Dropdown (ABAP WEBDYNPRO)

    Hi Experts,
    I am using dropdown as a table field. For this dropdown I want to display the value as well as description.
    In ALV table when we create a dropdown dynamically in table field, there is a method SET_KEY_VISIBLE in class CL_SALV_WD_UIE_DROPDOWN_BY_KEY.
    But I think we cannot use similar method for normal dropdown field in table.
    Is there any way we can display both value and description in dropdown value set ?
    Please help.
    Regards,
    Anand

    Hi,
    I think there is no such option. You need to consider one variable type string and while populating the
    valueset fill this variable by concatenating the value and description and assign it the key and value
    pair of the valueset.
    DATA:
      lt_value_set_ctry      type table of wdr_context_attr_value, " Country/Service Location
      lv_str type string.
        loop at lit_country into ls_country.
          concatenate ls_country-value ls_country-text into lv_str separated by space.
          ls_value_set-value = lv_str.
          ls_value_set-text  = lv_str.
          append  ls_value_set to lt_value_set_ctry.
          clear ls_value_set.
        endloop.
          lr_node_info->set_attribute_value_set( name = 'COUNTRY'
                     value_set = lt_value_set_ctry ).
    Consider this lit_country is a text table for countries.
    Regards,
    Lekha.

  • Desperately seeking help!! IE Crashes using Swing Applet

    Hi,
    I've created a grid applet using JTable and Swing in an applet. It runs great with data from a SQL database. I have at least 3 instances of the grid on the same page and other places on the site.
    However, Internet Explorer crashes frequently throwing an error "Unhandled exception at xxxxxxx in IExplore.exe (Beans.ocx).
    And the behavior is random and unpredictable.
    I've been desperately trying to look for help to fix this.
    Could someone please, please offer some suggestion?
    Thanks in advance,
    Anand.

    I agree. Try upgrading your plug-in version to 1.3.1. Keep in mind though that after 1.3.0, Sun changed where the plug-in looks for the root certificate. If you're using a Verisign or Thawte certificate, you shouldn't have any problems. If you're using your own certificate, you'll probably need to import it into the cacerts file in the lib/security directory under the installation directory of your jre.
    Hope this helps,
    Mark

  • Canvas or Form for displaying images

    Hi all,
    I am experiencing an annoying problem.
    I am developing an image viewer in J2ME/MIDP. I displayed all images in thumbnails. I don�t know how to list them. In canvas � I�ve problem with scrolling, if I use Form, I don�t know how to put more than one image per row. Maybe I have to use CustomItem in Form?
    Thanks for your replies.

    What you can try is:
    1. Insert default .jpg picture into your report
    2. Right-click the image and select Format Graphic> select Pictures tab> Graphic Location formula
    3. Insert your formula, but make sure that result of your formula is a string - full pass to .jpg file
    I have tested it right now and it works for my CRXIr2.

Maybe you are looking for

  • New to Blackberry family. Having email issues.

    Ok gang, I'm sure you are tired of helping people with this matter but my wife bought me a Curve recently. I upgraded my hotmail account to a hotmail plus account.so that i could get the emails on my phone. For some reason everytime I get a email it

  • Weird "relay access denied" error when using "%" in email address

    Hi, I've written a solution that allows emails to be processed and redirected through my mail server. First, we receive mail at user%[email protected]. Then, we do some checks to make sure its legit, alter its content and re-send it t

  • Canon EOS 350D .CR2 pics still 'unsupported image format'?

    I was releaved to see updates in Mac OS X (10.4.8) and Aperture 1.5 the other week, hoping it would solve my problem, being able to finally work with my RAW files (.cr2) from the Canon EOS 350D (yes, being in Europe these days). I followed the posts

  • CCMS setup on a Microsoft Clustered Environment

    Hi All, I am in the process of setting up CCMS alerts in the Central system(Sol Man) on a Microsoft Clustered environment. The Satellite systems that I want to add to the Central system are Microsoft Clustered. Can anyone help me with the steps or do

  • Adding a target to link

    I am using the following action script with a movie clip. But the link is opening in a new window or browser tab. I want it to open in the same window or browser tab as the flash insert is on. What do I need to do?