Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-10-2008, 11:27 PM
Member
 
Join Date: Jun 2008
Posts: 8
serfster is on a distinguished road
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:
Code:
static JLabel[] labelname = new JLabel [20] (imageIconHere);
Help?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-11-2008, 04:13 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
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...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +3. The time now is 02:45 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org