Make a GUI display an image

Im having trouble adding an image to a GUI, ive tryed adding it the same way I would add a JLabel (seeing as there both swing components, i asumed it would work) but it wont work, heres my code.
import javax.swing.*;
import java.awt.*;
public class HelloWorldSwing
    private static void createAndShowGUI()
        JFrame frame = new JFrame("My Gui");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 50);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        ImageIcon image = new ImageIcon("Logo", "C:/Windows/System32/oobe/images/mslogo.jpg" );
        frame.getContentPane().add(image);
        frame.validate();
        frame.setVisible(true);
    public static void main(String[] args)
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}What am I doing wrong ?

Im having trouble adding an image to a GUI, ive tryed
adding it the same way I would add a JLabel (seeing
as there both swing components...An ImageIcon does not inherit from Component. You cannot add an ImageIcon with add()...

Similar Messages

  • The Header in my home page is truncated. My home page Header is cut off. The header appears in Internet Explorer, but not in Mozilla Firefox 3.6.13. How to make the header display in Firefox?

    The Header in my home page is truncated. My home page Header is cut off. The header appears in Internet Explorer, but not in Mozilla Firefox 3.6.13. How do make the header display?

    (Images or animations do not show) worked well.

  • Displaying a image in a gui

    i was wondering how i can display an image using jframe
    what steps would i need to take to get it working

    Yes, there are several ways you can get an image icon either from local disk or network. I have used the simplest approach and shown here how to display an image in user interface.
    As suggested by DrLaszloJamf, using URL is good approach. Locate your image, construct the URL and then create the image icon using that URL.
    Sample code for creating image icon:
         * Locates the image icon at specified {@code path} using given class reference
         * and a short description of the image.
         * Once the URL is resolved it creates an image icon and returns the same.
         * @param cl The class which is used as reference to locate the image icon.
         * @param path The pathname for the image.
         * @param description A brief textual description of the image.
         * @return An image icon. It returns {@code null} if given path can not be resolved
         *               or failed to load the image icon.
        public static ImageIcon createImageIcon(Class cl, String path,
                String description) {
            // Validate inputs here.
            try {
                URL imgURL = cl.getResource(path);
                if (description != null) {
                    return new ImageIcon(imgURL, description);
                } else {
                    return new ImageIcon(imgURL);
            } catch (Exception ex) {
                ex.printStackTrace();
                return null;
        }Thanks,
    Mrityunjoy
    Edited by: mrityunjoy on 6 Feb, 2009 10:22 AM

  • Noob GUI question - Display an Image from a file

    I've done a bit of Java before but never a user interface. To start I'm just trying to display an image in a Panel, and can't even get that far!
    Here is my code (all the relevant bits of it...), would be much appreciated if someone could explain why it doesn't work. (Just so you know, breakpoints have shown that the code IS getting to the end of the 'try' block successfully)
    public class PictureBox extends Canvas {
        private Image m_image;
        public PictureBox()
            m_image = null;
        public PictureBox(Image image)
            m_image = image;
        public void setImage(Image image)
            m_image = image;
        @Override public void paint(Graphics g)
            if(m_image != null)
                g.drawImage(m_image, 0, 0, this);
        private void initialise()
            m_pb = new PictureBox();
            jPanel1.add(m_pb);
            jPanel1.add(new JButton());
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            try
                jFileChooser1.showOpenDialog(jPanel1);
                File f = jFileChooser1.getSelectedFile();
                m_image = ImageIO.read(f);
                m_pb.setImage(m_image);
                m_pb.repaint();
            catch(Exception e)
                return;
        }

    I don't know which resource you are using as a guide, but throw it away immediately. You are using AWT here, I would highly recommend you switch to Swing. It has a very nice tutorial that will get you up and running in no time:
    http://java.sun.com/docs/books/tutorial/uiswing/

  • How to make simple GUI application that use oracle 9i intermedia

    Mr Lawrence,
    i want to make a GUI application for storing and retrieving image data, can i build this application using delphi?
    i try using borland delphi 7, but delphi doesnt know object type ORDImage and ORDImageSignature. do u have any reference about building GUI application??
    I want my application can do inserting image into database, searching image by matching it's signature, make image signature for query image, displaying image, etc.
    Or if i can't make this application using delphi, maybe u can give me another application developer beside Delphi.
    Please help Mr Lawrence, i'm stuck (T_T)

    I am not too familiar with Delphi.
    If it does Object-Relational types, that could work.
    Can it interface with PL/SQL procedures? If so, that would be the way to go.
    That is what I have done with .NET applications.
    Larry

  • Display BLOB (image) column in (interactive) report

    Hi,
    I have a field called "picture" in my table "details" which is of type BLOB. i also have a field for "MIMETYPE" and "filename"
    i additionally have a "name" and "description" columns which i need to display along with the picture as columns in a report (preferably interactive).
    i have also modified the BLOB display format as per
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r31/apex31nf/apex31blob.htm
    what i am missing is the correct query. if possible, i would like to control the size of the picture rendered within the report like say 40*50.
    I have also referred to the thread
    APEX 3.1 Display BLOB Image
    But i don't know how to place the
    dbms_lob.getlength("BLOB_CONTENT") as "BLOB_CONTENT"
    in my query.
    The above also makes the report column as of type "number". is this expected?
    Any help would be much appreciated.
    Regards,
    Ramakrishnan

    You haven't actually said what the problem is?
    >
    I have a field called "picture" in my table "details" which is of type BLOB. i also have a field for "MIMETYPE" and "filename"
    i additionally have a "name" and "description" columns which i need to display along with the picture as columns in a report (preferably interactive).
    i have also modified the BLOB display format as per
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r31/apex31nf/apex31blob.htm
    what i am missing is the correct query.
    I have also referred to the thread
    APEX 3.1 Display BLOB Image
    But i don't know how to place the
    dbms_lob.getlength("BLOB_CONTENT") as "BLOB_CONTENT"
    >
    Something like:
    select
              name
            , description
            , dbms_lob.getlength(picture) picture
    from
              details
    if possible, i would like to control the size of the picture rendered within the report like say 40*50.For images close to this size it's easy to do this for declarative BLOB images in interactive reports using CSS. Add a style sheet with:
    .apexir_WORKSHEET_DATA td[headers="PICTURE"] img {
      display: block;
      width: 40px;
      border: 1px solid #999;
      padding: 4px;
      background: #f6f6f6;
    }where the <tt>PICTURE</tt> value in the attribute selector is the table header ID of the image column. Setting only one dimension (in this case the width) scales the image with the correct aspect ratio. (The border, padding and background properties are just eye candy...)
    However, scaling large images in the browser this way is a huge waste of bandwidth and produces poorer quality images than creating proper scaled down versions using image tools. For improved performance and image quality, and where you require image-specific scaling you can use the database ORDImage object to produce thumbnail and preview versions automatically, as described in this blog post.

  • Displaying an image from a URL

    I have a program which visits a html page and creates a JComboBox with all the images from that page. When the user selects an image from the combo box it displays that image in a JLabel. This works fine with images that exist, when I try it with an image that doesn't exist I want it to realise that and display a message saying that "the image cannot be found". Heres part of my code that handles the selection:
    public void actionPerformed(ActionEvent f) {
                        JComboBox cb = (JComboBox)f.getSource();
                        String imageName = (String)cb.getSelectedItem();
                        try {
                             imageUrl = new URL(imageName);
                        catch (MalformedURLException ex) {
                             System.out.println("Image Collection Error: " + ex);
                        catch (Exception e) {
                             System.out.println("Some sort of exception: " + e);
                        picture.setIcon(new ImageIcon(imageUrl));
              });When I select a bad link image from the list I was hoping the catch blocks would trap it and I could make adjustments accordingly, this does not happen. No exception is thrown at all.
    Any ideas of what I can do??
    Bow_wow.

    Thanks for your help, I have changed it to the following code:
    ImageIcon imageToDisplay = new ImageIcon(imageUrl);
                        ImageIcon badImage = new ImageIcon("logo.jpg"); // An image I know exists
                        int status = imageToDisplay.getImageLoadStatus();
                        if (status == MediaTracker.COMPLETE) {
                             picture.setIcon(imageToDisplay);
                        else {
                             picture.setIcon(badImage);                              
                        }It works now, thanks again for your help!

  • Display Icon/Image instead of Role name in top level navigation

    Hi,
    I want to display a image / icon instead of role name for a particular role. Can you please tell me how to achieve this ?
    Thanks,
    VP

    Hi,
    the thread is just for the background image (for all elements).
    if you want to display icons instead of role names, you have to create your custom top level navigation using the
    navigation taglib from SAP. There are lots of examples. make a blog search for Mr "Kannengiesser" from SAP.
    In case you are using already an EHPx in your EP 7.0 the AJAX framework might have this feature.
    Regards,
    Kai

  • [Forum FAQ] How to display an image from Http response in Reporting Services?

    Question:
    There is a kind of scenario that users want to display an image which is from URL. In Reporting Services, if the URL points to an image file, we can directly display it by typing the URL in embedded image. However, some URLs are just sending Http requests
    to server side, then redirect to another position and the server will return the image. For these kind of URLs, Reporting Services can’t directly render the image from Http response.
    Answer:
    To achieve this goal, we can add custom code into the report. Pass the URL as argument into our custom function so that we can create HttpRequest and get the HttpResponse. Then we can use custom function to return the Bytes() from the HttpResponse and render
    it into an image in report.
    Ps: In Reporting Services, it only support drawing Bytes() array into image, so we need to have our custom function return Bytes array.
    Add the assembly and custom code into the report.
    Public shared Function GetImageFromByte(Byval URL as String) As byte() 
                    Dim photo as System.Drawing.Image 
             Dim Request As System.Net.HttpWebRequest 
           Dim Response As System.Net.HttpWebResponse 
                  Request = System.Net.WebRequest.Create(URL)         
                     Response = CType(Request.GetResponse, System.Net.WebResponse) 
                 If Request.HaveResponse Then  
                      If Response.StatusCode = Net.HttpStatusCode.OK Then                    
                           photo = System.Drawing.Image.FromStream(Response.GetResponseStream) 
                     End If 
                 End If 
                  Dim ms AS System.IO.MemoryStream = new System.IO.MemoryStream() 
                 photo.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg) 
                    Dim imagedata as byte()  
                    imagedata = ms.GetBuffer()  
                    return imagedata
    End Function
    Grant the permission for assemblies. 
    Go to: 
    C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\RSpreviewPolicy.config 
    C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\rssrvpolicy.config
    Give “FullTrust” for Report_Expressions_Default_Permissions.
    Insert an image into report. 
    Expression:
    =Code.GetImageFromByte("https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSrVwPoAtlcA2A3KaiAJi-XjS4icr1QUnKYr7uzpX3IL3g2GPisAQ")
    The Result looks below:
    Applies to:
    Reporting Services 2005
    Reporting Services 2008
    Reporting Services 2008 R2
    Reporting Services 2012
    Reporting Services 2014
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    >
    Hi, I'd like to display a dynamic image from the web inside a JLabel or any other swing component it could work in. I've been looking on the Swing tutorials and others forums, all I can have is that a JLabel can load an Icon object, defined by an image URL, but can this URL be like "http://xxxxx/image.jpg" somehow or can it only be a local image URL?>
    I do not know why you start talking about an image on the web then go on to show concerns about whether it will work for a 'local' URL.
    But perhaps this answer will cover the possibilities.
    So long as you can from an URL to the image, and the bytes are available for download (e.g. some web sites wrap a direct call to an image in HTML that embeds the image), the URL based icon constructors will successfully load it.
    It does not matter if that URL points to
    - a web site,
    - a local server ('localhost'),
    - an URL representation of a File on the local file system, or
    - it is inside a Jar file that is on the application's run-time classpath.
    How you go about forming a valid URL to a 'local resources' (or indeed what you regard as local resources) is another matter, depending on the form of the project, and how the resources are stored (see list above).
    Probably the main reason that examples use images at a hard coded URL on the net is that it makes an 'image example' self contained. As soon as we compile and run it, we can see the result. I have posted a few examples like that on these forums.
    Edit 1:
    BTW - Welcome to the Sun forums
    Edited by: AndrewThompson64 on Apr 21, 2009 12:15 PM

  • Adobe reader not displaying the images

    I am trying to open pdf document includes with the images. Text is showing correctly but the images are grayed out. I can open same document with images in Nitro Pro but not with Adobe, that means no issue with the file damaging.

    Hi shahabk,
    Please make sure that Show Large Images in selected in the Page Display preferences. Choose Edit > Preferences (Windows) or Reader > Preferences (Mac OS), and then click the Page Display category. The Show Large Images option is about half-way down the dialog box.
    Best,
    Sara

  • Problems displaying an image on Adobe Reader 8.1.2

    Hi guys,
    We are trying to display a JPG image in an InteractiveForm. So, we set an Image (StaticImage) to be loaded using the following Formcalc script on Page Initialize event:
    StaticImage1.value.image.href = $record.ImageURL
    On our last project, we could display a JPG image with Adobe Reader 6 (with some alert messages), 7 and 8 (7 and 8 fully functional). But in this one, the same solution doesn't work. The unique difference between both solutions is the URL format. Last project displays an image based on a normal URL ("http://app.client.com/photo/1234.jpg"), and in the current project we create a PNG or JPG image based on a JFreeChart, generating an URL to access it ("http://server1:54321/webdynpro/resources/vendor.com/..(long)../graph43211234.jpg").
    When we load it using a computer with Adobe Reader 7.0.x installed, the bellow message is displayed requesting an action:
    "Acrobat is attempting to connect to the site:
    http://server1:54321/webdynpro/resources/vendor.com/..(long)../graph43211234.jpg
    If you trust the site click "Allow", otherwise click "Block".
    Possible actions: Block, Allow and a check "Remember my action for the site: server1"
    Allowing the connection, the images are displayed. But, in a machine with Adobe Reader 8.1.2 installed, sometimes it asks for permission to access the URL, sometimes not. And, in both cases, in this version it doesn't display the images...
    Can anyone shed any light on this? Also, is there a way to block this annoying message?
    Regards,
    Douglas Frankenberger
    P.S.:
    1 - The Image is not marked as Embedded. This option don't seems to make any difference, as on our last project the StaticImage was not flaged as Embed, but the JPG file was embeded in the PDF anyway...
    2 - Interactive Form display type: native. Mode: updateDataInPDF
    3 - In current project, when we set the same image the we had set on the old project, it loads successfully. Also, the generated JFreeChart image is fully accessible when displayed directly in IE using its URL.
    4 - Versions:
      - Client: Windows XP Professional
      - NWDS 7.0.10
      - Adobe Livecycle 7.0.50519.0
      - Adobe Reader: 7.0.8, 7.0.9 and 8.1.2

    Hi Amita.
    We already tried it (checked / unchecked), but it seems to make no difference. There is a strange behavion on this:
    - When I set it checked, on a computer disconnected from the web and running Adobe Reader 7.0.9, it asks for permission to access a resource (as I said before). In this case, even disconnected, it shows up my image independent of allowing/blocking the access to the external resource. In other words, it is embedded (I think...), but continues asking for access anyway.
    - The same scenery above, but using Adobe Reader 8.1.2 instead of 7.0.9.... sometimes it asks for permission, sometimes not. But in both cases, it doesn't display the images...
    Regards,
    Douglas Frankenberger

  • How to display the Image in PDF report by using iText Report

    Hi
    Im trying to display the image which is very big one.
    This is my code
    Document document=new Document();
    PdfWriter.getInstance(document,new FileOutputStream("imagePDF.pdf"));
    document.open();
    Image image = Image.getInstance ("1.bmp");
    document.add(new Paragraph("Images in PDF"));
    document.add(image);
    document.close();
    But the image "1.bmp" is displayed partially. Its not spanning to the next page.
    Can anyone help me to solve this one?
    Thanks in Advance
    dhilip

    Do you actually want the image to span multiple pages? I am not sure that will be possible without splitting the image; the itext mailing list would be the place to ask.
    You could make the the page size big enough for the image using Document.setPageSize()

  • Can an Acrobat form have a field that allows you to select and display an image?

    Hello,
      I'm trying to streamline my most frequent job duty. I work for a box plant and I spend most of my day creating or updating Print Cards. These are letter sized pages that contain the job information along the top and an image of the package laid flat below. What I'm trying to do is make the Print Card a form that I can fill in, and have the final field ask me to select the image. I would then browse for my package design and drop it into the specified field.
      Is this possible? It seems like it should be. I'm fairly illustrator savvy, but I've yet to really get my hands on Acrobat (though I get more excited about it the more research I do).
      Eventually, I want to turn this single form into a full portfolio that would be linked pdf versions of every form we currently use. The info would then be uploaded and assessable by anyone on our team. I don't know how to do half of that, but I'm learning.   So I guess, expect to see me post on this for a while.
    -Jefferson

    Yes, you can set up a button that has a layout other than "Label only" and  use the following as the Mouse Up JavaScript for the button:
    // Mouse Up script for button
    event.target.buttonImportIcon();
    You will then be prompted to select a file as the source of the button icon. You can choose form a number of file types. You should then set the button to read-only before sending the PDF.
    To trigger the import from a different button, bookmark, link, etc., the script would be:
    getField("image_button").buttonImportIcon();
    Replace "image_button" with the actual name of the button that will display the image.

  • How to retain focus in Web forms 6i item when displaying pdf image

    How to retain focus in Web forms 6i item when displaying pdf image in a multi-record block?
    Hello.
    I have a Web Forms 6i program (version Forms 6.0.8.19.2) running in a 3-tier application. The web form program has a multi-record block containing invoices. When navigating to a record, the form should display the PDF invoice image which is stored in an Oracle 8.1.7 database as a BLOB in another window. When user press down-arrow, the next PDF invoice image should be displayed.
    I am able to accomplish the functionality above by using web.show_document('URL', target') in the when-new-record-instance. The URL being called is a PL/SQL Web Toolkit stored procedure using wpg_docload.download_file built-in.
    The problem is that the focus is lost on the Webform and the focus is shifted to the PDF image window when you navigate to the next record using down-arrow. I want to retain the focus in the form as this is a data-entry form, the operator will use down-arrow to go to the next-record rather than the mouse. I also only want to do this for this Invoice Entry form and NOT to all forms.
    Please advise how to resolve this problem. Thank you.
    Regards,
    Armando

    Magesh,
    the issue of a SSO protected form showing the logon dialog is a knwon issue for Windows200 and the Oracle9iAS base release. If you applied Forms Patch 1 then this should be solved. Hope that I am right in that you are using Oracle9iAS and not Oracle9iDS. Do you see the Single Sign-On logon screen or the Forms logon dialog directly? Check the forms90.conf file in teh forms90/server directory as this contains the Form sso settings (mod_osso) which by default is commented out and therefore inactive. You need to remove the commenting '#' characters and make sure that each sentence having a '#' in front, after that starts on a new line.
    The Forms deployment documentation within the Oracle9iAS docu provides this information too.
    Frank

  • Why has Lightroom 4 stopped displaying my images?

    I was scrolling through my image libary in thumbnail mode - quite fast as I was looking for certain groups of images to keyword them.  I had been doing this for some time and then suddenly it just stopped displaying the images - the thumbnails were just empty.  I thought they would render after a few seconds but they didn't.  I then scrolled back up and none of the images were being displayed.  Lightroom would then not close properly so I had to force quit.  Computer wouldn't shut down properly either - I assume Lightroom was still doing something in the background.  When I restarted the computer and opened Lightroom the same problem was the same - no images at all being displayed.  Everything seems fine on the hard drive when I look outside of Lightroom so the images are there, and all the folders are still in place in the Lightroom catalogue - just not displaying images.  Any ideas?

    Re-installing LR very rarely changes anything...
    Did you install some other software recently?
    Is your preferences file ok? ...just thinking of one *of the usual suspects*... [on Win7  C:\Users\<youruser>\AppData\Roaming\Adobe\Lightroom\Preferences\Lightroom 4 Preferences.agprefs] ... you can rename the existing one and let LR recreate a new one.
    Recreating as suggested above would not mean your total catalog, but all your previews - if we suspect the previews folder of corruption.
    Speaking of usual suspects: try the last backups of your catalog, if they show the same behaviour? ...to rule out some corruption of your working catalog...
    You optimize your catalog regularly, e.g. before creating the backup? If not, you could also try that.
    If none of your catalogs works, then create a fresh test catalog and import a few images and render their previews, to see if it is actually your LR installation with the problem.
    Did you try LR4.3RC already? This might make more sense than re-installing an older version.
    Good luck, Cornelia

Maybe you are looking for