Using JLabel[] to create an array of image labels

Hello, I am quite new to Java so I am not sure if the following is even the best way to do what i am trying to do ... but please advise:
I am making a JLayeredPane mapArea with grid lines where the user will be able to change the scale of the map and the grid lines can move along. The way I approached it is to create JLabel arrays that contains every single gird line i am going to use, add them to the map panel at the bottom-most layer and position them according to the scale. Below is the code that I wrote:
int i = 0;     //local index variable for the for loops below
JLabel[] vlineArray = new JLabel[50];
JLabel[] hlineArray = new JLabel[50];
ImageIcon[] vlineImageArray = new ImageIcon[50];
ImageIcon[] hlineImageArray = new ImageIcon[50];
for( i=0; i<50; i++ ){
     vlineImageArray[ i ] = new ImageIcon(GUI.class.getResource("vline.gif")); 
     hlineImageArray[ i ] = new ImageIcon(GUI.class.getResource("hline.gif")); 
// vertical line array
     for( i=0; i<50; i++){
     vlineArray [ i ] = new JLabel(vlineImageArray[ i ]);
mapArea.add(vlineArray[ i ],1);
// horizontal line array
for( i=0; i<50; i++){
     hlineArray [ i ]= new JLabel(hlineImageArray[ i ]);
     mapArea.add(hlineArray [ i ],1);
}}I tried to position these Jlabels in the array using setBounds:
i.e. vlineArray.setBounds(......)
But nothing showed... But if I simple create a vline by itself and add it to the map pane and setBounds. The vline shows up fine:
// this works
JLabel vlineImage = new JLabel(vline);
mapArea.add(vlineImage);
vlineImage.setBounds(.....);I also tried to post at the java programming forum
http://forum.java.sun.com/thread.jspa?threadID=646495&tstart=15
But nothing worked.
Please help! Thanks a bunch!

if I were going to draw grid lines over a map area, I would put a component the size of the layered pane in the layered pane which is transparent and can be given a scale and can override the paint method to paint the lines directly instead of trying to handle lots of labels like you're doing.

Similar Messages

  • How do I create an Array of Images

    Hi,
    I'm creating a program that basically is a slideshow. It has buttons that allow the user to switch from image to image, and has some audio in the background. I was wondering how I might create an array to store the images. I'm very new to Java, so please no detail is too small. I've just started using arrays, so I'm not sure where I would store the files or how to call the images. Please be descriptive and as dumbed down as possible :)
    Thanks for the help!

    I like ArrayList
    ArrayList<BufferedImage> myPics = new ArrayList();then just dump them in with add(myBufferedImage)
    If you'e not using BufferedImages then just change the BufferedImage to Image.
    to get, say the 6th image back out, then use:
    myBufferedImage = myPics.get(5);the index starts at 0 and should be addressed as 0 to (myPics.length - 1)

  • How to use HorizontalList populated with an Array of Image?

    Is it possible to populate a HorizontalList with an Array of
    Image? I am trying to create a HorizontaList of Images (thumbnails)
    using a dynamic method where I put each thumbnails found into an
    Array and then indicating to the HorizontalList to use the Array as
    the dataProvider. The result is that I just see the ID generated
    for each Image.
    Since I am controlling the content of the HorizontalList into
    the mx:source, I am a bit confused how to use the itemRenderer
    property.
    Any help will be appreciated since Google don't show a lot of
    example/problems like mine at this moment!

    Hi,
    Just set the itemRenderer property to mx.controls.Image and
    you should be done.

  • Please help - I can not create large arrays of images (no more than 108 elements)

    Hello,
    I am working in an application where i acquire 300 high resolution images (3Mp) and then i process each of those frames.
    When i try to put alll those frames in one array of images, the system does not let me more than 108 elements. There is no such message like out of memory or memory error. It is just that when i visualize the array of images, there are good frames the first 108 elements, and then white frames the rest of the elements.
    Ideallically i would prefer to process frames as i am acquiring them, but i am concerned about the remaining processing time for the rest of the tasks.
    Then, as an alternative, I have tried to store frames in two shorter arrays, and i ended up observing that when the first array (say 50 elements) is full and the second array starts (another 50 elements for example), labview needs a certain time in the the middle (like three seconds between closing first array and starting acquiring on the second array). If i dont wait that time between arrays, both arrays contain the same information. I know, this is weird, and i know about the fact of passing information by reference on imaq images. 
    The most interesting thing is that when i reduce considerably the resolution of the image (say that now, instead 3Mp they are 2Mp), the maximum number of elements on the arrays are exactly the same: 108, so this makes me wonder if it is a memory constrain. And the code is fairly simple, there is no way that i am cutting the acquisition at the number 108.
    So my question is, How can i put 300 frames in one just one array? or How can eliminate the time i have to wait between arrays?
    I have heard about memory allocation and so, but i am not sure how to proceed. I have windows 7.
    Thanks in advance,
    Roberto

    It's hard to visualize.  Please post the code - or at least a shell representing your code - so we can see what is happening.  Are you sure you are getting 108 contiguous pictures, or are some aquisitions being skipped?  Is the first picture in the array the first aqcuisition?  Is the last picture the last acquisition?
    I really don't think it is about memory allocation.  I think it could be about your method of acquiring and processing said acquisitions.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • How to use xpress to create an array?

    I am trying to delete some accounts in workflow. When I try to get all these accounts from repository. I find in com.waveset.session.session,the method listUsers(Attributecondition[] conds) is the best for me. But I don't know how to create an array of type attributecondition.
    Can somebody help me?

    just invoke toarray method on java.util.arrayList by passing attribute conditions as list...
    Attribute conditions are just example only..
    <invoke name='toArray' class=java.util.ArrayList>
    <list>
    <new class='com.waveset.object.AttributeCondition'>
    <s>name</s>
    <s>startsWith</s>
    <ref>taskNameStartsWith</ref>
    </new>
    <new class='com.waveset.object.AttributeCondition'>
    <s>state</s>
    <s>in</s>
    <list>
    <s>SUSPENDED</s>
    <s>EXECUTING</s>
    <s>READY</s>
    </list>
    </new>
    </list>
    </invoke>

  • Create a new Buffered Image using Raster and ColorModel

    Sorry , I crosspost this message,because no one reply.
    Recently,I write a programme combining C++ and Java .
    The C++ part create a array containing image data in form of BI_RGB and biBitCount==32.
    The java part create a image using Raster and ColorModel like this:
       static int[] data ;
       DataBuffer db = new DataBufferInt(data, data.length);
       WritableRaster wr =Raster.createPackedRaster(db, 1024,768, 32, null);
       ColorModel cm = new DirectColorModel(32,0xff0000,0x00ff00,0x0000ff);
       img = new BufferedImage(cm, wr, false, null);But it doesn't work .
    it report this:
    Exception in thread "main" java.lang.IllegalArgumentException: Raster sun.awt.im
    age.SunWritableRaster@dff3a2 is incompatible with ColorModel DirectColorModel: r
    mask=ff0000 gmask=ff00 bmask=ff amask=0
    at java.awt.image.BufferedImage.<init>(BufferedImage.java:549)
    at monitor.test.Perform2.main(Perform2.java:39)

    hey epico
    compiles & runs 4 me
    see javadocs for SinglePixelPackedSampleModel
    import java.awt.image.*;
    public class Tester {
    DataBuffer db;
    WritableRaster wr;
    ColorModel cm;
    BufferedImage im;
    int[] data;
    int[] masks;
    int w = 768;
    int h = 576;
      public Tester() {
        data = new int[768*576];
        for (int i = 0;i < w*h ;i++ ) {
          data[i] = 0;
        masks = new int[3];
        masks[0] = 0xff0000;
        masks[1] = 0x00ff00;
        masks[2] = 0x0000ff;
        db = new DataBufferInt(data,data.length);
        SinglePixelPackedSampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,w,h,masks);
        cm = new DirectColorModel(32,0xff0000,0x00ff00,0x0000ff);
        wr = Raster.createWritableRaster(sm,db,null);
        im = new BufferedImage(cm,wr,false,null);
      public static void main(String[] args) {
        Tester tester1 = new Tester();
    }

  • Creating an array of jpg images

    hi. i want to create an array of jpg images and wrap them in an arrayCollection which will serve as the dataprovider for a TileList...
    the images are located in a "asset" folder within the src folder...tried both actionscript and mx tags and can't figure out how to create an array of images.
    thanx.

    You need to use ItemRenderers to display images in list based controls.
    Here is an example in mxml
    <mx:TileList>
            <mx:dataProvider>
                <mx:ArrayCollection>
                    <mx:Array>
                        <mx:Object source="assets/image1.jpg"/>
                        <mx:Object source="assets/image2.jpg"/>
                        <mx:Object source="assets/image3.jpg"/>
                    </mx:Array>
                </mx:ArrayCollection>
            </mx:dataProvider>
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Image source="{data.source}"/>
                </mx:Component>
            </mx:itemRenderer>
        </mx:TileList>    
    Check this livedocs page
    http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_8.html

  • Null pointer exception- with array of images

    Hi , i am having some problems with my program. I am trying to create an array of images( which i dont really know how to do) and i keep getting this error
    Exception in thread "main" java.lang.NullPointerException
    at DiceRoller.<init>(DiceRoller.java:35)
    at RollDice.main(RollDice.java:19)
    Here is my code, any help would be appreciated, i have switched things around and i still can't figure out what is wrong
    * @(#)RollDice.java
    * RollDice application
    * @author
    * @version 1.00 2009/3/23
    import java.util.Scanner;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class RollDice {
        public static void main(String[] args) {
             DiceRoller diceroller  = new DiceRoller();
             //Default Close operations
             diceroller.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
             //Size
            diceroller.setSize( 121, 121 ); // set frame size
            //Dont want anyone to mess with it
            diceroller.setResizable(false); // Cant resize
            diceroller.setVisible( true ); // display frame
    * Dice.java
    //Main dice Class
    import java.util.Random;
    import java.io.*;
    public class Dice
         public      Random r = new Random();
         private int sides;
         private int rolls;
         public int x;
         public Dice()
         Roll method
         public int roll()
              x=0;
              x = (r.nextInt(6)+1);
              return x;
    /** DiceRoller.java
    * Roll, print, Gui
    import javax.swing.*;
    public class DiceRoller extends JFrame
         private ImageIcon[] image = null ;
         public String[] images = { "empty", "dice1.jpg",
                   "dice2.jpg", "dice3.jpg", "dice4.jpg",
                   "dice5.jpg", "dice6.jpg" };
         public Dice die;
         private int rollVal;
         public int rollNum;
         private JLabel j1;
         public DiceRoller(){
           die =new Dice();
           int rollVal = 0;
           rollVal = die.roll();     
           //Images     
           image = new ImageIcon[images.length];
          for(int i = 0; i < images.length; i++){
          image[i] = new ImageIcon(images);
    }//end for
    // setImage(rollVal);
         if (image!=null){
              j1.setIcon(image[rollVal]);
         System.out.println("Roll = "+die.roll());

    max_wallace wrote:
    Do you think you could please elaborate on your answer, and what does borked mean?One of my favourite words that; [b0rked|http://www.urbandictionary.com/define.php?term=b0rked] / borked

  • How do you create an array without using a shell on the FP?

    I want to be able to read the status of front panel controls (value, control box selection, etc.) and save it to a file, as a "configuration" file -- then be able to load it and have all the controls set to the same states as were saved in the file. I was thinking an array would be a way to do this, as I have done that in VB. (Saving it as a text file, then reading lines back into the array when the file is read and point the control(s) values/states to the corresponding array element.
    So how do I create an array of X dimensions without using a shell on the front panel? Or can someone suggest a better way to accomplish what I am after? (Datalogging doesn't allow for saving the status by a filename, so I
    do not want to go that route.)

    Thanks so much m3nth! This definitely looks like what I was wanting... just not really knowing how to get there.
    I'm not sure I follow all the icons. Is that an array (top left with 0 constant) in the top example? And if so, that gets back to part of my original question of how to create an array without using a shell on the FP. Do I follow your diagram correctly?
    If I seem a tad green... well I am.
    I hope you understand the LabVIEW environment and icons are still very new to me.
    Also, I had a response from an NI app. engineer about this problem. He sent me a couple of VI's that he threw together approaching this by using Keys. (I still think you are pointing to the best solution.) I assume he wouldn't mind m
    e posting his reply and the VI's for the sake of a good, thorough, Roundtable discussion. So here are his comments with VI's attached:
    "I was implementing this exact functionality this morning for an application I'm working on. I only have five controls I want to save, but they are all of different data types. I simply wrote a key for each control, and read back that key on initialization. I simply passed in property node values to the save VI at the end, and passed the values out to property nodes at
    the beginning. I've attached my initialize and save VI's for you to view. If you have so many controls that this would not be feasible, you may want to look into clustering the controls and saving the cluster as a datalog file.
    Attachments:
    Initialize_Settings.vi ‏55 KB
    Save_Settings.vi ‏52 KB

  • How to add byte[] array based Image to the SQL Server without using parameter

    how to add byte[] array based Image to the SQL Server without using parameter.I have a column in table with the type image in sql and i want to add image array to the sql image column like below:
    I want to add image (RESIM) to the procedur like shown above but sql accepts byte[] RESIMI like System.Drowing. I whant that  sql accepts byte [] array like sql  image type
    not using cmd.ParametersAdd() method
    here is Isle() method content

    SQL Server binary constants use a hexadecimal format:
    https://msdn.microsoft.com/en-us/library/ms179899.aspx
    You'll have to build that string from a byte array yourself:
    byte[] bytes = ...
    StringBuilder builder = new StringBuilder("0x", 2 + bytes.Length * 2);
    foreach (var b in bytes)
    builder.Append(b.ToString("X2"));
    string binhex = builder.ToString();
    That said, what you're trying to do - not using parameters - is the wrong thing to do. Not only it is insecure due to the risk of SQL injection but in the case of binary data is also inefficient since these hex strings are larger than the original byte[]
    data.

  • "Using a CIN to Create an Array of Strings in LabVIEW" example crashes LV on Linux

    Tried to utilize this NI example: "Using a CIN to Create an Array of Strings in LabVIEW" (http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B4B282BE7EF907C8E034080020E74861&p_node=&p_source=External)
    Compiles OK with the makefile made by the LV's lvmkmf utility. Nevertheless when I try to run the VI (with the code loaded into the CIN, of course), LabVIEW 7.1.1 on a SUSE 9.3 Linux machine crashes:
    LabVIEW caught fatal signal
    7.1.1 - Received SIGSEGV
    Reason: address not mapped to object
    Attempt to reference address: 0x0
    Segmentation fault
    Any ideas? Did anybody try this on a Windows machine?

    H View Labs wrote:
    Tried to utilize this NI example: "Using a CIN to Create an Array of Strings in LabVIEW" (http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B4B282BE7EF907C8E034080020E74861&p_node=&p_source=External)
    Compiles OK with the makefile made by the LV's lvmkmf utility. Nevertheless when I try to run the VI (with the code loaded into the CIN, of course), LabVIEW 7.1.1 on a SUSE 9.3 Linux machine crashes:
    LabVIEW caught fatal signal
    7.1.1 - Received SIGSEGV
    Reason: address not mapped to object
    Attempt to reference address: 0x0
    Segmentation fault
    Any ideas? Did anybody try this on a Windows machine?
    This code is badly broken. In addition to resizing the actual handle to hold the number of string handles you also would need to create the string handles itself before attempting to write into them. NumericArrayResize is the fucntion to use as it will either resize an existing handle (if any) or create a new one if the value is uninitialized (NULL).
    /* resize strarr to hold handles to NUMSTRINGS strings */
    err = SetCINArraySize((UHandle)strarr, 0, NUMSTRINGS);
    if (err)
    goto out;
    /* perform this loop once for each element */
    /* of array of strings being created */
    for (i = 0; i < NUMSTRINGS;) {
    LStrHandle handle = (*strarr)->arg1[i];
    /* determine length of string that will be element of strarr */
    strsize = StrLen(str[i]);
    err = NumericArrayResize(uB, 1, &handle, strsize);
    if (err)
    goto out;
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /* moves strsize bytes from the address pointed to */
    /* by str[i] to the address pointed to by the data pointer in the handle */
    MoveBlock(str[i], LStrBuf(*handle), strsize);
    /* manually set size of string pointed to by *strarr */
    (*((*strarr)->arg1[i]))->cnt = strsize;
    /* manually set dimSize of strarr */
    (*strarr)->dimSize = ++i;
    return noErr;
    out:
    return err;
    Rolf KalbermatterMessage Edited by rolfk on 06-30-2005 03:15 AM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to create an array using reflection.

    How to create an array using reflection.
    I want to achive something like this,Object o;
    o = (Object)(new TestClass[10]);but by use of reflection.
    To create a single object is simple:Object o;
    o = Class.forName("TestClass").newInstance();But how do I create an array of objects, when the class of objects is known only by name? (Can't use Object[] because even though an Object[] array can be filled with "TestClass" elements only, it Cannot be casted to a TestClass[] array)
    Anybody knows?":-)
    Ragnvald Barth
    Software enigneer

    Found it!
    the java.lang.reflect.Array class solves it!
    Yes !!!

  • What is the best way to create diagonal array in order to avoid MEMORY IS FULL error created by using INITIALIZE ARRAY vi?

    Using the values in a 1D array, I need to place them along the diagonal of a 2D array. Currently, I've been using INITIALIZE ARRAY VI to create 2D array of zeroes and then usE REPLACE ARRAY SUBSET to put the 1D array values on the diagonal. This works sometimes but I often get an error stating that the memory is full and that the application was stopped at INITIALIZE ARRAY.
    I'd appreciate any advice on how to stop this from occuring.
    Thanks and happy holidays,
    Hunter (LabView 6.1 user)

    Weather is the same here, too.
    Sorry about the PDF. I had forgotten about the PRTSCN option. See the attached JPG.
    I'd send you an example input that is giving me problems but today, my computer seems to be behaving and the error hasn't popped up. This makes me believe that it's truly a memory problem with my machine.
    This VI is a subVI used in several computationally intensive applications.
    If you're still interested in playing with it, I will email it to you. Please send me your address. In fact, I see you're in the oil & gas industry and I'd like to hear what you're working on since I work in that industry as well.
    Thanks again, Hunter ([email protected])
    Attachments:
    VI_Diagram.jpg ‏104 KB

  • Displaying Image using JLabel in swings

    I am not understanding how to display a image in swing using JLabel Component.
    I am writing in the following manner:
    // importing necessary packages
    in init() method
    public void init()
    Container cp= getContentPane()
    JLabel jl=new JLabel("Image",new ImageIcon("<image>.gif"),JLabel.CENTER);
    cp.add(jl);
    applet is running and only label msg is displaying but not the image.
    Please help me so that i can solve this problem.where the image is to be placed??and how it has to be included?
    Please provide me the solution.

    cp.add(new JLabel("Image",new ImageIcon(new java.net.URL (getCodeBase(),"Test.gif")),JLabel.CENTER));

  • Creating a Windows 7 Image using AIK

    Hey All
    I am currently in a process of trying to create an image in my company that I can deploy on identical machines (Toshiba R830).  I have currently re-installed one laptop from manufacturer’s partition, but I would like to now create an identical image
    (WIM file) that I can deploy easily to other identical laptops in case user’s get a virus or whatever the case may be.
    In short I wanted to find out if it’s possible to copy all the partitions that the manufacturer has created on the machine into an image, since I do not want to deviate from manufacturer’s process and still want to have their particular set-up replicated
     when I re-image machines.
    I have tried to go through the re-imaging process but there is so many tools, ways and things to do before you can create an image that I am just lost in the sea of information provided.
    I just want to have an image on the network identical to the current set-up on the host laptop.  I have downloaded AIK for windows 7 and have tried to create bootable USB stick without much success.
    My current set-up is:
    Windows 7 Professional x64: (Running off the manufacturers Microsoft Windows activation key) According to Microsoft you cannot run an 'answer file' on a single OS license, you need to have a corporate license agreement in place with Microsoft.
    I do not have access to Windows OS media as my image was restored from a manufacturer's rescue partition (Out of box Experience) and then I modified the set-up via SysPrep 'System Audit' mode to how I want an image to look like.  According to Microsoft
    you are required to have either an ISO or an OS disk to use an 'answer file' for automated deployment.
    There are 3 partitions on the machine and I would like to take all 3 of them to the new image (not sure if this is possible).  
    Furthermore, do I have to set-up every new laptop HD partitions to conform with exact layout partition parameters as an initial image file using the WinPE media (as suggested by Microsoft) or is there an easier way of doing this, short of creating 'answer
    file' which  I cant't do due to above reasons? 
    I am struggling with creating windows PE bootable USB stick, any help on this would be much appreciated.
    How can I create unattended installation without use of windows 7 media, corporate license key, etc.  As this will be getting deployed to many users I need this to be unattended.
    The tutorials I watched on-line seem to be awfully complicated for creating and deploying simple image that is supposed to save you time not be longer than installing from Windows OS disk.
    Any help would be appreciated.
    Regards
    Slav 

    Hey Arnav,
    Thank you for your prompt response.  Yes, I did go through this but specified method requires a DVD media for Windows 7 (Which we are not using, we are using a manufacturer's restore partition), and an answer file does not automate without Windows corporate
    license key according to Microsoft (which we dont have, we are using the manufacturer's keys assigned per device basis).  
    Additionally, we have 3 partitions on the host image machine (put there by Manufacturer) which we would like to translate to our final image, and there doesn't appear to be any instructions on how to package these partitions into a WIM file for future image
    deployments.
    Many thanks,
    Regards
    Slav

Maybe you are looking for

  • Iphone not syncing to itunes unknown error -50

    My iPhone 4S isn't sycing to iTunes, I get the "Uknown Error (-50)" ...it won't let me update my iPhone either...help anyone?!

  • Split module usage in mail adapter

    hi,      Can anyone explain whts the usage of Splitmail module in mail adapter? The Scenario for the  interface is IDOC to Mail. IDOC is transformed by XI and mapped to a target message, and then it is send as a mail with file attachment to various c

  • Complaints from customers

    Hi all, We have two big complaints from our customers concerning the checkout process. 1: Netpoint will not let the customer continue until they have labeled and saved their address information.  Some customers don't want to save this information.  T

  • Printing from iphoto 09

    When I try to print from iphoto, I get the message "No available themes located. Until at least one theme has been installed this feature will be unavailable" What is a theme, and how do I instal one?

  • BOXI3.0: Formula for subtract/deduct one day or more from date field

    Greetings. Its Alias. I have one question. Actually I already post this question but at designer forum. I am using SQL. Example I have Order Date field and from this field I want to subtract the date by minus one day or two days or three days, etc. I