Results 1 to 2 of 2

Thread: JLabel Array?

  1. #1
    serfster is offline Member
    Join Date
    Jun 2008
    Rep Power

    Default JLabel Array?

    I just started learning Java! I am trying to create an array of JLabels. Is this possible? I cannot seem to get the code right. I plan to have them all display the same icon.

    I tried this code to declare the array, but it is most certainly incorrect:
    Java Code:
    static JLabel[] labelname = new JLabel [20] (imageIconHere);

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    Java Code:
    ImageIcon icon = new ImageIcon(imagePath);
    // allocate array for 20 labels
    JLabel[] labels = new JLabel[20];
    // all elements of this array are null, not instantiated
    // initialize the array by instantiating the elements
    for(int i = 0; i < labels.length; i++) {
        labels[i] = new JLabel(icon);
    // labels are ready to go...

Similar Threads

  1. GUI - JLabel
    By Azndaddy in forum New To Java
    Replies: 8
    Last Post: 05-02-2008, 08:03 AM
  2. help me with JFrame and JLabel
    By michcio in forum New To Java
    Replies: 5
    Last Post: 11-20-2007, 08:44 AM
  3. How to use JLabel with html
    By leonard in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 05:43 PM
  4. JLabel
    By Jack in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 02:55 PM
  5. JLabel
    By Freddie in forum AWT / Swing
    Replies: 2
    Last Post: 05-29-2007, 03:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts