How to add multiple images to a JLabel from the jar file

I want to add multiple images in a JLabel but the icon property only allows me to add one. I thought I could use html rendering to add the images I need by using the <img> tab, but I need to use a URL that points to the image.
How do I point to an image inside the jar file? If I can't, is there another way to show multiple images in a JLabel from the jar file?

Thanks, it works perfectly. It's a really smart way of fixing the problem too :)
I also found your toggle button icon classes which is something I've also had a problem with.
Thanks.

Similar Messages

  • How to add multiple images in jinternalframe

    Hi all,
    how to add multiple images to the jinternalframe, at specified location of the pane and resizing the images with specified height and width.
    code examples are highly appreciated.
    Thanks & Regards,
    Abel

    Thanks, it works perfectly. It's a really smart way of fixing the problem too :)
    I also found your toggle button icon classes which is something I've also had a problem with.
    Thanks.

  • Loading an image into an Applet from a JAR file

    Hello everyone, hopefully a simple question for someone to help me with!
    Im trying to load some images into an applet, currently it uses the JApplet.getImage(url) method just before registering with a media tracker, which works but for the sake of efficiency I would prefer the images all to be contained in the jar file as oppossed to being loaded individually from the server.
    Say I have a class in a package eg, 'com.mydomain.myapplet.class.bin' and an images contained in the file structure 'com.mydomain.myapplet.images.img.gif' how do I load it (and waiting for it to be loaded before preceeding?
    I've seen lots of info of the web for this but much of it is very old (pre 2000) and im sure things have changed a little since then.
    Thanks for any help!

    I don't touch applets, so I can't help you there, but here's some Friday Fun: tracking image loading.
    import java.awt.*;
    import java.awt.image.*;
    import java.beans.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.imageio.event.*;
    import javax.imageio.stream.*;
    import javax.swing.*;
    public class ImageLoader extends SwingWorker<BufferedImage, Void> {
        private URL url;
        private JLabel target;
        private IIOReadProgressAdapter listener = new IIOReadProgressAdapter() {
            @Override public void imageProgress(ImageReader source, float percentageDone) {
                setProgress((int)percentageDone);
            @Override public void imageComplete(ImageReader source) {
                setProgress(100);
        public ImageLoader(URL url, JLabel target) {
            this.url = url;
            this.target = target;
        @Override protected BufferedImage doInBackground() throws IOException {
            ImageInputStream input = ImageIO.createImageInputStream(url.openStream());
            try {
                ImageReader reader = ImageIO.getImageReaders(input).next();
                reader.addIIOReadProgressListener(listener);
                reader.setInput(input);
                return reader.read(0);
            } finally {
                input.close();
        @Override protected void done() {
            try {
                target.setIcon(new ImageIcon(get()));
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);
        //demo
        public static void main(String[] args) throws IOException {
            final URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot.jpg");
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch(url);
        static void launch(URL url) {
            JLabel imageLabel = new JLabel();
            final JProgressBar progress = new JProgressBar();
            progress.setBorderPainted(true);
            progress.setStringPainted(true);
            JScrollPane scroller = new JScrollPane(imageLabel);
            scroller.setPreferredSize(new Dimension(800,600));
            JPanel content = new JPanel(new BorderLayout());
            content.add(scroller, BorderLayout.CENTER);
            content.add(progress, BorderLayout.SOUTH);
            JFrame f = new JFrame("ImageLoader");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(content);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            ImageLoader loader = new ImageLoader(url, imageLabel);
            loader.addPropertyChangeListener( new PropertyChangeListener() {
                 public  void propertyChange(PropertyChangeEvent evt) {
                     if ("progress".equals(evt.getPropertyName())) {
                         progress.setValue((Integer)evt.getNewValue());
                         System.out.println(evt.getNewValue());
                     } else if ("state".equals(evt.getPropertyName())) {
                         if (SwingWorker.StateValue.DONE == evt.getNewValue()) {
                             progress.setIndeterminate(true);
            loader.execute();
    abstract class IIOReadProgressAdapter implements IIOReadProgressListener {
        @Override public void imageComplete(ImageReader source) {}
        @Override public void imageProgress(ImageReader source, float percentageDone) {}
        @Override public void imageStarted(ImageReader source, int imageIndex) {}
        @Override public void readAborted(ImageReader source) {}
        @Override public void sequenceComplete(ImageReader source) {}
        @Override public void sequenceStarted(ImageReader source, int minIndex) {}
        @Override public void thumbnailComplete(ImageReader source) {}
        @Override public void thumbnailProgress(ImageReader source, float percentageDone) {}
        @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) {}
    }

  • How to add multiple images to panel

    Hi, i am trying to add more than 1 image to a panel, but i cant work out how. have the following code, but it means i have to create a new panel each time. i only want to use 1 panel, and add images to this one panel. the images are transparent and i layer them over each other. I mouse listener to get the coordinates when the user clicks over the image, and for this i need to use a panel, unless anyone can show me another way????
    cheers for any advice,
    ness
    public class test extends Applet
    DrawPanel dp;
    public void init()
    Image im1 = getImage(getDocumentBase(),"images/panel1.gif");
    Image im2 = getImage(getDocumentBase(),"images/front.gif");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(im1,0);
    mt.addImage(im2,0);
    try{mt.waitForAll();}
    catch(InterruptedException ie){}
    dp = new DrawPanel(im1);
    //here i want to add im2 image to dp panel but how???????
    setLayout(new BorderLayout());
    add(BorderLayout.CENTER,dp);
    class DrawPanel extends Panel
    Image im;
    Image im1;
    Image im2;
    public DrawPanel(Image im)
    im = im;
    public void paint(Graphics g)
    if (im != null)
    g.drawImage(im1,0,0,this);
    g.drawImage(im2, 20, 20, this);

    I've modified the code so that you can send DrawPanel an array of images where index 0 in the array will be draw on the bottom and 1 on top of that, 2 on top of that, and so on. You'll need to add the 20,20 offset somewhere if you want to include that too. Good Luck!
    public class test extends Applet
        DrawPanel dp;
        public void init()
            Image im1 =
            getImage(getDocumentBase(),"images/panel1.gif");
            Image im2 = getImage(getDocumentBase(),"images/front.gif");
            MediaTracker mt = new MediaTracker(this);
            mt.addImage(im1,0);
            mt.addImage(im2,0);
            try{mt.waitForAll();}
            catch(InterruptedException ie){}
            /** Declare array and place two images in it **/
            Image[] images = new Image[2];
            images[0] = im1;
            images[1] = im2;
            dp = new DrawPanel(images);
            setLayout(new BorderLayout());
            add(BorderLayout.CENTER,dp);
    class DrawPanel extends Panel
        Image[] ims;
        public DrawPanel(Image[] im)
            ims = im;
        public void paint(Graphics g)
            super.paint(g);
            for(int i=0; i<ims.length; i++)
                if (ims[i] != null) g.drawImage(ims,0,0,this);

  • How to add an image or static text in the header of EACH page of a cross-Tab report

    Post Author: rtutus
    CA Forum: General
    Hi, I use Crustal 11.0.
    I have a cross Tab. I display the items on the left column and the months horizontally, the items are grouped by category field. The values are the sum of quantities are displayed for each month. Like this:
                             Items         Jan       Feb       March .....................Total
    Category 1                       
                             Item11         val11     Val12      Val13                     Total values
                             Item12         val21     Val22      Val23                     Total values
                             Item13         val31     Val32      Val33                     Total values
    Category 2                       
                             Item21         val11     Val12      Val13                     Total values
                             Item22         val21     Val22      Val23                     Total values
                             Item23         val31     Val32      Val33                     Total values
    Category 3                       
                             Item31         val11     Val12      Val13                     Total values
                             Item32         val21     Val22      Val23                     Total values
                             Item33         val31     Val32      Val33                     Total values
    The problem, I want to add a page header for each page of the report.
    When Crystal reports first displays my cross-tab in the designer, CR displays the cross tab in the Report header section. I d like to add text or image for each page and not only at the begining of my Cross-Tab.
    If I just add an image or text at the top of the report designer, which is my report header, I get the image or text only on the begining of the 1st page of my report but never in the other following pages.
    If I try to work around the problem and move the cross Tab to a group section instead, and then put the Image in the group header, I get what I want, but the problem is that:
    The columns header: Jan, February....December are displayed for each group of my report and not only in the beginning of the report. I get something like this:
                             Items         Jan       Feb       March .....................Total
    Category 1                       
                             Item11         val11     Val12      Val13                     Total values
                             Item12         val21     Val22      Val23                     Total values
                             Item13         val31     Val32      Val33                     Total values
                             Items         Jan       Feb       March .....................Total
    Category 2                       
                             Item21         val11     Val12      Val13                     Total values
                             Item22         val21     Val22      Val23                     Total values
                             Item23         val31     Val32      Val33                     Total values
                             Items         Jan       Feb       March .....................Total
    Category 3                       
                             Item31         val11     Val12      Val13                     Total values
                             Item32         val21     Val22      Val23                     Total values
                             Item33         val31     Val32      Val33                     Total values
    You see the months get duplicated. Any way, my real need is to add an image or text in the header of EACH page of a cross-Tab report.
    Thanks a lot for your help.

    Hi Divya,
    you could do for example in the wdDoInit() of the view
    wdContext.currentContextElement().setPicture("picture.gif");
    Now you assign this context variable to the Tab using the Tab_header's imageSource-Property. When you click on its value column, you see a button with three dots on it. If you click on this button, you will get all context nodes and attributes for this View. Usable variables are clearly marked, you now choose the one named Picture or what ever name you prefer to use. But it must correspond to the one set in the wdDoInit.
    I think setting a picture (not necessarily for the tab-page) is done in one of the excellent tutorials. If you are a newcomer I strongly recommend doing some of the tutorials.  I have learned tremendously from them.
    Hope this helped
    Harald

  • How to add music videos that are not from the itunes store?

    This drives me CRAZY that iTunes will allow me to classify my .mp4 music videos that I get from other sources (NOT bought from the iTunes store) as a Music Video but iTunes STILL keeps it classified under the Movie listing. Does anyone know how I go about or what is needed to get my music video files in the Music Video list?
    While I'm at it...
    It also bugs me that I can't organize my library properly. For example, I have a music performance/concert video and instead of having it in a separate list of "Musical Performances", iTunes contains it under Movies. This is a first for me to complain about my iTunes experience but I just wish there would be some flexibility for me to add content and categorize/list it under my personal preferences. Anything wrong with that?

    If you go to the Get Info menu and set Video Kind to Music Video it will only appear in your music library, and not in the Movie section.
    The tool VideoDrive (www.aroona.net) will automatically classify all your videos when you import them in iTunes, based on file and folder name, the length of the video and other metadata...

  • How can I save images and text data to the same file?

    I have been looking at ways to do this for a while. My main VI saves the raw data to a text file which the users then import to Excel and plot. I am trying to simplify this process and have been looking at ways to accomplish this task. I want to be able to save the raw data to a file and then save the Labview graph as well. This will eliminate the tedious task of importing the raw data into Excel and plotting it. I can save the raw data to its own file and I can use the Get Image method for the graph and save it to its own file. I am currently using the .png format. Is there a way of saving both to the same file ie, importing the image into Excel or Word etc. Before I go off doing a science project I wanted to see if anyone else had experience completing this task and had any recommendations. Thanks in advance for any help.

    well ther are a couple of ways. You could use the standard report generation VI's and make a complete report with the image of the graph embedded into the report with the raw data or you could use activeX and control excel thru LV and put the raw data into excel directly and have excel graph the data without any user interaction. I have posted a slew of VI's on the excel board if you do not have the report generation toolkit. If you could tell me which way you want to go I could possibly send you an example.
    For more information and some sample VI's and tool kits, you can go to the excel board
    Joe.
    "NOTHING IS EVER EASY"

  • How to open files in MIDP (from the jar file)?

    Hello,
    I can't seem to figure out how to open a file that is in my MIDP applications jar-File.
    From what I've found via Google, I assume that the way to do it should be by using
    Connector.openInputStream("file:{path_to_my_file}")
    but I only get the error
    java.lang.ClassNotFoundException: com.sun.midp.io.j2me.file.Protocol
    (Running the Emulator from Suns WTK 2.0 with DefaultColorPhone)
    I've also tried file:// with the same result.
    Any ideas?
    Many thanks in advance!
    Bjoern

    I think I've found something that looks promising now:
    Class.getResourceAsStream()

  • How to SQL*loader to skip some columns from the source file?

    I am using oracle9i sqlldr to load some .csv files into db.
    If I want to skip the first two columns in the source file, can I do that?
    If yes, how should I specify it in the ctl file?
    Thanks
    Wendy

    Hello Dave,
    Here is a sample of what you'll need to have in your control fileLOAD DATA
    APPEND
    INTO TABLE <target_table>
    FIELDS TERMINATED BY ','
    ( column_1  FILLER
    , column_2
    , column_3
    , column_4  FILLER
    )Hope this helps,
    Luke

  • How to get a data element's value from the data file while bursting

    For faxing bursted data into rightafx, I need to first burst my invoice data file into numerous pdf files in the filesystem, and then use the rightfax function of the delivery manager to send those files to different faxes. Integration with rightfax is not available in the bursting engine.
    While bursting the xml data file based on invoice number, I need to get the fax number that is different for each invoice in a java variable so that I can use it to pass fax number information to rightfax. Is it possible?
    Thanks.

    Can any one help?
    Edited by: MTW on Apr 16, 2010 6:58 AM

  • How to know which class is being loaded from which jar file & path location

    Hi,
    I have some Java code using several jar files.
    I want to remove those jar files which are not being used by the code.
    So , I want the JVM to output which class is being loaded from which jar .
    Using "java -verbose" option doesnt solve the problem because the required info is printed only for the classes/jars native to the J2SE package .
    Can anyone provide a solution which does not require me to modify the code?
    Thanks,
    Danish

    Classpath Helper

  • How do I add multiple images into one file?

    I'm sure this is something that's been covered in another post (or even in the help portal) but I think my wording in my search terms are not correct or... I don't know, because I just can't find what I'm looking for.
    I want to know how to add multiple images into one file/one image, both horizontally and/or vertically. To give you an idea of what I mean, check out :
    http://www.best10apps.com/apps/comic-story,531596060.html
    If you scroll down, you'll see a heading entitled : Screenshots of Comic Story. Notice how there's 3 pictures (divided by borders). 2 of those pictures are side by side, and 1 of them is below the first 2 pictures.
    I want to know how to add different pictures/images and put them into one picture.

    One way is to create template PSD files and populate them with your images using Photoshops scripts.
    Photo Collage Toolkit UPDATED June 12, added Picture Package Support via PasteImageRoll and BatchPicturePackage scripts.
    The package includes four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.
    There are eleven scripts in this package they provide the following functions:
    TestCollageTemplate.jsx - Used to test a Photo Collage Template while you are making it with Photoshop.
    CollageTemplateBuilder.jsx - Can build Templates compatible with this toolkit's scripts.
    LayerToAlphaChan.jsx - Used to convert a Prototype Image Layer stack into a template document.
    InteractivePopulateCollage.jsx - Used to interactively populate Any Photo Collage template. Offers most user control inserting pictures and text.
    ReplaceCollageImage.jsx - use to replace a populated collage image Smart Object layer with an other image correctly resized and positioned.
    ChangeTextSize.jsx - This script can be used to change Image stamps text size when the size used by the populating did not work well.
    PopulateCollageTemplate.jsx - Used to Automatically populate a Photo Collage template and leave the populated copy open in Photoshop.
    BatchOneImageCollage.jsx - Used to Automatically Batch Populate Collage templates that only have one image inserted. The Collage or Image may be stamped with text.
    BatchMultiImageCollage.jsx - Used to Automatically Batch Populate Any Photo Collage template with images in a source image folder. Easier to use than the interactive script. Saved collages can be tweaked.
    BatchPicturePackage.jsx - Used to Automatically Batch Populate Any Photo Collage template with an image in a source image folder
    PasteImageRoll.jsx - Paste Images into a document to be print on roll paper.
    Documentation and Examples

  • How to import multiple images at the same time in illustrator?

    How to import multiple images in a document at the same time in illustrator?
    It's possible?

    Script: Place Multiple Files in Illustrator (Kelso)
    http://kelsocartography.com/blog/?p=2047

  • How do I read the images I bundled into the jar file?

    I just wrote an applet that uses
         Toolkit tk = Toolkit.getDefaultToolkit();
         tk.getImage("blah.gif");to load a bunch of image files. The class file and gif images were bundled into a jar file to minimize the number of connections the browser has to make to the server.
    The applet works fine in appletviewer but trips a java.security.AccessControlException: access denied (java.io.FilePermission select.gif read) when run in a browser. I know you normally use Applet.getImage(URL) to load images but wont that circumvent the JAR file and make a seperate connection to the server for each image? That would defeat the purpose of using a JAR file.
    How do I access the image files I bundled into the JAR file?

    From your Applet class, write the following:
    URL imgUrl = getClass().getResource("blah.gif");
    Image img = getImage(imgUrl);The returned URL will be from the Applet class ClassLoader, which will look into the specified archive (jar) file.

  • How to read, write file inside the JAR file?

    Hi all,
    I want to read the file inside the jar file, use following method:
    File file = new File("filename");
    It works if not in JAR file, but it doesn't work if it's in a JAR file.
    I found someone had the same problem, but no reply.
    http://forum.java.sun.com/thread.jsp?forum=22&thread=180618
    Can you help me ? I have tried this for all night !
    Thanks in advance
    Leo

    If you want to read a file from the JAR file that the
    application is packaged in (rather than a separate
    external JAR file) you do it like this ...
    InputStream is =
    ClassLoader.getSystemResourceAsStream("filename");Better to use
    this.getClass().getClassLoader().getResourceAsStream();
    From a class near to where the data is. This deals with multiple classloaders properly.

Maybe you are looking for