Question about adding multiple components....

.....HI, i really hope someone can help out......
When I try to add mutilple components to the panel, it won't show the components that I have added before again.....
For example, I have a Icon Label and I want it to show two of the same Label again in the panel.... but it won't... it will just show one of them....
for example:
Label[] dice = new Label[6]
Icon bug[] = new Icon[6];
String dicePics[] = {"1.jpg", "2.jpg","3.jpg",
"4.jpg","5.jpg","6.jpg",};
for(int i=0; i<6; i++){
bug[i] = new ImageIcon(dicePics);
dice[i] = new JLabel();
dice[i].setIcon( bug[i] );
userPanel.add(dice[0]);
userPanel.add(dice[0]);
This will only show dice[0] once in panel........ how can I show the same things over again in a panel more then once.........?? I also try it on other things... when adding a component with same name, it will just show one of them.......... wondering if someone can help me out.......

.....HI, i really hope someone can help out......
When I try to add mutilple components to the panel,
it won't show the components that I have added before
again.....
For example, I have a Icon Label and I want it to
show two of the same Label again in the panel.... but
it won't... it will just show one of them....
for example:
Label[] dice = new Label[6]
Icon bug[] = new Icon[6];
String dicePics[] = {"1.jpg", "2.jpg","3.jpg",
"4.jpg","5.jpg","6.jpg",};
for(int i=0; i<6; i++){
bug[i] = new ImageIcon(dicePics);
dice[i] = new JLabel();
dice[i].setIcon( bug[i] );
l.add(dice[0]);
userPanel.add(dice[0]);
This will only show dice[0] once in panel........ how
can I show the same things over again in a panel more
then once.........?? I also try it on other
things... when adding a component with same name, it
will just show one of them.......... wondering if
someone can help me out.......
You can't add the same GUI object to a Container multiple times. The problem is with your design. Consider something like this:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class DieLabelTest {
    private Random rand = new Random();
    private final JLabel[] dies = new JLabel[6];
    DieLabelTest() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel diePanel = new JPanel(new GridLayout(3,0,5,5));
        for (int i = 0; i < 6; i++) {
            dies[i] = new JLabel();
            dies.setIcon(DieIconProvider.getIcon(rand.nextInt(6) + 1));
diePanel.add(dies[i]);
f.add(diePanel, BorderLayout.CENTER);
JButton rollButton = new JButton("Roll");
rollButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
for (int i = 0; i < 6; i++) {
dies[i].setIcon(DieIconProvider.getIcon(rand.nextInt(6) + 1));
f.add(rollButton, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
public static void main(String[] args) {
new DieLabelTest();
class DieIconProvider {
private static Icon[] icons = new Icon[6];
public static synchronized Icon getIcon(int num) {
if (icons[num - 1] == null) {
icons[num - 1] = new ImageIcon(num + ".jpg");
return icons[num -1];

Similar Messages

  • How would I go about adding multiple rectangles using the same lines of code?

    How would I go about adding multiple rectangles using the same lines of code? I would prefer to just run through a set of code every time I need a polygon. If I just have to create multiple polygon adding statements that's fine but I'd prefer just 1.

    >>How would I go about adding multiple rectangles using the same lines of code?
    You could create a method that creates and returns x number of Rectangle elements:
    public IEnumerable<Rectangle> CreateRectangles(int numberOfRectsToCreate)
    for (int i = 0; i < numberOfRectsToCreate; ++i)
    Rectangle rect = new Rectangle();
    rect.Fill = Brushes.Blue;
    rect.Width = 100;
    rect.Height = 100;
    yield return rect;
    ..and then call this method from anywhere in your code:
    IEnumerable<Rectangle> rects = CreateRectangles(5);
    foreach (Rectangle rect in rects)
    //add to StackPanel or do whatever with the Rectangle elements:
    yourStackPanel.Children.Add(rect);
    >>If I just have to create multiple polygon adding statements that's fine but I'd prefer just 1.
    When adding Point objects to a Polygon you can only add one per call to the Add method but you could call the Add method inside a loop, e.g:
    for(int i = 0; i < 10; ++i)
    //add to StackPanel or do whatever with the Rectangle elements:
    Polygon p = new Polygon();
    p.Points.Add(new Point());
    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't post several questions in the same thread.

  • I have a question about using multiple ipads in our school.  Each of our teachers have a iPad and AppleTV in their classroom.  The issue is, with our classrooms so close in proximity to one another, is there a way to pair teacher

    I have a question about using multiple ipads in our school.  Each of our teachers have a iPad and AppleTV in their classroom.  The issue is, with our classrooms so close in proximity to one another, is there a way to pair teacher #1 iPad to its AppleTV without effecting/projecting onto the adjacent teachers #2 classroom AppleTV?

    Not as such.
    Give the AppleTV units unique names and also enable Airplay password in settings with unique passwords for each teacher.
    AC

  • Question About Adding Ram from other laptop to T-series Thinkpad

    Hi,
    I have a question about adding additional RAM. Right now I have a 4gb ram stick in the t510. I have an acer laptop which I do not need and there is a 4GB ram stick onboard (maybe two 2gb ram sticks) there in that older laptop. Would it be possible to add one stick of 2gb ram (or 4gb i need to check if it is 2 or 1) from the acer to the lenovo thinkpad making the total ram in the thinkpad over 4gb????
    Thanks in advance

    Hi Richk,
    Yes, I am using a 64-bit operating system. I am running on windows 7. And as for reported incompatibilities....technically taking a RAM from another laptop and placing it in the laptop should be the same as purchasing a RAM card from ebay or something and putting into the laptop right?

  • Questions about adding files in LR3

    I've been a happy LR user for years. I used the LR3 beta and liked it (especially the 2nd version) and generally I'm very happy with the release version of LR3. But I have some questions about the import process.
    In LR2 I could edit off my Compact Flash cards (I know that's not smart, but sometimes on deadline fast is better than not smart) by adding the photos my library without moving them. That option is grayed out in LR3. Is there a way to turn it on or is this is a "new feature." If it's a permanent thing, maybe for 3.1 or the next incremental upgrade Adobe could make this possible with a popup (like we get when adding captions to multiple files) warning that editing photos on a CF (or SD) card is a bad idea. But let us make the decision.
    jack

    It's a deliberate change - time to adjust the workflow!
    John

  • Question about using multiple iPods on the same PC

    I've read the FAQs on this subject but I still have a couple of questions about multiple users with separate iPods using the same PC.
    I want to use my family's desktop (A new Gateway with Vista, if it matters) for my new iPod Classic, but my father already has an iTunes account on there for his iPod. I know I can create a new user account on the PC and move iTunes to a shared folder so that we can share music, but will this second account be able to purchase music from the iTunes store or am I going to have to switch between Windows User accounts to make purchases and then move new songs into my separate iTunes account via the shared folder? Will it be its own separate iTunes account (separate user name, separate credit card used, etc.) or will it just be a second library that's dependant on the first?
    I want to be able to have my own iTunes account, make my own purchases in it, and maybe occasionally share tv shows or something with my father.
    If this can't be done, would I be better off just creating new playlists for our two iPods from the same library, or creating a second library on my Father's account?
    Also, if I want to access things I've purchased from iTunes on this desktop in iTunes on my notebook, will I be able to?
    I hope that made sense.
    Sorry if these seem like silly questions. This will be my first iPod as I'm really excited about the 160gig and want to know if these things are possible.
    Thanks in advance for any help

    Hi, Wes.
    Congratulations on your new iPod Classic and Welcome to the Apple Discussions.
    For no particular reason, let's answer your last question first ...
    ... if I want to access things I've purchased from iTunes on this desktop in iTunes on my notebook, will I be able to?
    The iTunes Store operates on a one download per purchase policy so you will have to copy the purchases from one computer to the other and make sure that you authorize the laptop to play the songs.
    As to your first question ...
    ... will this second account be able to purchase music from the iTunes store or am I going to have to switch between Windows User accounts to make purchases ...
    Whatever XP User Account you are logged in to doesn't really matter. What's important is which Apple Account you sign in to ... yours or your Dad's or - if you had my Apple ID and password - The Mimico Kid's for that matter. You can sign in to any Apple Account on any XP User Account. Or any computer for that matter.
    Where the XP User Account comes into play is that it will determine where on your computer the purchases are downloaded. Files will be sent to the iTunes Music folder as specified in the iTunes Edit menu > Preferences > Advanced tab > General sub-tab. Default settings will have a different location for each User Account - C:\Documents and Settings\ user name \My Documents\My Music\iTunes - but if you've read this article in the Apple Knowledge Base, you will know you can change the location of the iTunes Music folder in each XP Account to a common location such as C:\Documents and Settings\All Users\Documents\My Music\iTunes.
    Post back if all this hasn't been as clear as mud and you need anything clarified.

  • JOptionPane: adding multiple Components

    Hello,
    I am trying to add multiple components to a JOption Pane. When the JOptionPane is displayed, the JOptionPane is not resized in order to display all of the components. In my case, the buttons of the JOptioPane are pushed down. Only the upper half of buttons are visible.
    How do you set the JOptionPane to fully display all of the objects that were passed into it?

    What do you mean by saying that the components should be added to the JPanel using the setBounds() method?
    I currently have this:
    JPanel p = new JPanel(null);
    p.add(new JLabel("Label"));
    p.add(new JEditorTextPane("text/plain", "Text"));
    p.add(new JTextField("Text field"));
    p.setBounds(new Rectangle(200, 200));
    JOptionPane.showOptionDialog(null, p, "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null);
    With this code, I do not even see the "OK" button. The dialog is not resizing correctly. Also, the components are getting laid out incorrectly in the JPanel. Everything is laid out from left to right.

  • Question about adding an index to a column and finding it back

    Hi, How do I see in phpMyAdmin that an index is added to a column.(I'm talking about adding an index by clicking on the lightning bolt!) I know how to add an index and see a warning that it's added (only after I add it).
    But where do I find it or a sign that it is added later on?!
    Thanks!

    You also may find better exposure for this question on the Dreamweaver Applications Development forum -
    http://forums.adobe.com/community/dreamweaver/dreamweaver_development

  • Adding multiple components in same direction ?

    Hi,
    I'm adding multiple child panels to a single parent panel. One of such child panel is "xPanel" as shown below. The problem is that all the 4 labels overlap each other i.e. main Panel only displays "11111" i.e the last JLabel added. I know that specifying direction (e.g BorderLayout.NORTH etc) will fix the overlap problem but I want all the lables in a single row i.e. XXXXX 00000 YYYYY 11111 ..... any suggestions how to fix this ?
              JPanel xPanel = new JPanel(new BorderLayout());
              xPanel .add(new JLabel("XXXXX:"));
              xPanel .add(new JLabel("00000"));
              xPanel .add(new JLabel("YYYYY:"));
              xPanel .add(new JLabel("11111"));
              mParentPanel.AddPanel(xPanel , BorderLayout.NORTH);          

    The default layout for a JPanel is the FlowLayout. Why did you change it do a BorderLayout?
    I suggest you read this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]Using Layout Managers so you understand how they work.

  • Another question about adding music to iPhone

    Apologies for yet another question regarding adding music to an iPhone but I am completely stuck.
    I bought a new laptop in January (it runs windows 8). I've authorised it and synced my phone to it before. I've used it to add music before.
    Lately I've just been buying music directly from itunes on my phone but I wanted to add some music from my older collection that is on an external harddrive.
    I've gone through the process of syncing the phone again, which has wiped whatever was on there. I made sure I'd ticked on the "manually manage music" box. 
    It's put all my purchased music back but it still will not let me drag and drop music from my external harddrive. When I hover over with the file it has "link" but it won't actually send the music to the phone.
    Is there a way for me to do this without putting music on to my itunes library? I don't like itunes and I definitely don't want to add the music to my laptop as it defeats the purpose of having an external harddrive! Sorry for such a long-winded explanation.

    Just to add... I've now tried adding music to the library (getting desperate here) and it's not letting me do that either. Just says 'link'.
    This is the most frustrating thing ever. Why are the simplest of tasks made so difficult? It seems like it only works if you buy the music from the iTunes store.

  • Question about syncing multiple ipods to one iTunes library

    I have an iPod touch (2nd gen Ver 3.1.3) that I sync to my computer. My daughter recently got an iPod touch (2nd gen Ver 4.0) that was under her father's account. I reset her iPod in order to put it under my iTunes store account. Next I synced her iPod with my computer adding only the items she wanted (games mostly and a few songs).
    iTunes didn't seem to have a problem with our devices being different versions. So far so good. I have only synced her device once and haven't synced mine since. We have both purchased apps straight to our iPods and they aren't backed up.
    My questions are:
    1. Before syncing, will I have to go check everything I want every time in iTunes?
    2. We use some of the same apps and games. Will the game data and/or app data be written by another players data? Can you tell I'm really just concerned about my TapFish score?
    I'm holding off on syncing until I know the answers.

    Nerdgirl98 wrote:
    1. Before syncing, will I have to go check everything I want every time in iTunes?
    well, it would be better to keep everything checked in your library and instead create separate playlists for each mobile device.
    click here for more information.
    2. We use some of the same apps and games. Will the game data and/or app data be written by another players data? Can you tell I'm really just concerned about my TapFish score?
    you can use as many mobile devices as you want with a single iTunes library. iTunes treats each device separately.
    i have two Nano's, an iPod Touch, and an iPad syncing with the same library.
    JGG

  • Question about adding an Extra Node to SOFS cluster

    Hi, I have a fully functioning SOFS cluster, with two nodes, it uses SAN FC storage, Not SAS JBODS. its running about 100VM's in production at the moment.
    Both my nodes currently sit on one blade chassis, but for resiliency, I want to add another node from a blade chassis in our secondary onsite smaller DC.
    I've done plenty of cluster node upgrades before on SQL and Hyper-V , but never with a SOFS cluster. 
    I have the third node fully prepaired, it can see the Disks the FC Luns, on the SAN (using powerpath, disk manager) and all the roles are installed.
    so in theory I can just add this node in the cluster manager and it should all be good, my question is has anyone else done this, and is there anything else I should be aware of, and what's the best way to check the new node will function , and be able
    to migrate the File role over without issues. I know I can run a validation when adding the node, I presume this is the best option ?
    cannot find much information on the web about expanding a SOFS cluster.
    any advice or information would be greatfully received !!
    cheers
    Mark

    Hi Mark,
    Sorry for the delay in reply.
    As you said there is no much information which related to add a node to a SOFS cluster.
    The only ones I could find is related to System Center (VMM):
    How to Add a Node to a Scale-Out File Server in VMM
    http://technet.microsoft.com/en-us/library/dn466530.aspx
    However adding a node to SOFS cluster should be simple as you just prepared. You can have a try and see the result. 
    If you have any feedback on our support, please send to [email protected]

  • Question about adding a line/phone to a new plan

    Hey everyone I have a concern I wanted to be clear about before I upgrade my plan. I am up for a device upgrade and plan on upgrading my smartphone and my current single line plan to one of of the new share everything family plans and a new smartphone. I can get the phone I want at a different store other then verizon for a better price so Im going to do that. After that is all said and done I plan on buying and adding another new smartphone/line to my share everything account through verizon(store or online). I just want to be sure that 1.) Adding another line after the fact isnt going to be a problem fee wise or the terms of my account wise since I just upgraded my account at a different vendor and 2.) Will that new line be still eligible for a upgrade discount through verizon just like a new plan would be even though Im not adding it at the same exact time I upgrade my main phone and plan?
    Also I was wondering that if..say a few months from now I want to add another new phone/line to my share everything account. Will that also be like a new plan and eligible for a upgrade discount through verizon? My 2.) question will probably answer this but I want to be absolutely sure first before I do anything. Thanks alot guys. Appreciate any input.

    scottm79 wrote:
    Hey everyone I have a concern I wanted to be clear about before I upgrade my plan. I am up for a device upgrade and plan on upgrading my smartphone and my current single line plan to one of of the new share everything family plans and a new smartphone. I can get the phone I want at a different store other then verizon for a better price so Im going to do that. After that is all said and done I plan on buying and adding another new smartphone/line to my share everything account through verizon(store or online). I just want to be sure that 1.) Adding another line after the fact isnt going to be a problem fee wise or the terms of my account wise since I just upgraded my account at a different vendor and 2.) Will that new line be still eligible for a upgrade discount through verizon just like a new plan would be even though Im not adding it at the same exact time I upgrade my main phone and plan?
    Also I was wondering that if..say a few months from now I want to add another new phone/line to my share everything account. Will that also be like a new plan and eligible for a upgrade discount through verizon? My 2.) question will probably answer this but I want to be absolutely sure first before I do anything. Thanks alot guys. Appreciate any input.
      Every time you add a line, it is eligible for a subsidized phone. It does not matter when you do it. As far as question #1, your account is just what the terms of usage is, not the length of the contract(s). Those are determined by the individual lines. You can also change the account limits at any time (eg. increase shared data limit), but when you do, it is usually pro-rated for the remainder of your current billing month, plus 1 month in advance. It does not change any of the lengths of the lines contracts.
      Does this help?

  • I have a question about airplay multiple speakers in Mountain lion

    I seem to be unable to use the "multiple speakers" feature in iTunes now that I've upgraded to Mountain Lion.  Before, I was able to stream music from my iTunes to two airport expresses throughout the house, simultaneoulsy with the computer's speakers.  Now it seems I can't. 
    When I select "multiple speakers" and click on the appropriate airport express, I get a dialog box that says "Connecting to Airport Express", which gives up after about 45 seconds of trying to connect. 
    Here are the things I've tried:
    1. In System Preferences, I've changed the audio output from computer to the airport express, which successfully sent the audio to the airport express.  But the system preferences audio tab just lets you select a single output destination, not multiple.  So I know that the speaker works, and that OSX still "likes" it.
    2. There has been mention on various boards that my computer no longer has the system requirements for this feature.  I want to know if that that's true.  (Full description of system below)
    3. I've used the trial of airfoil, which works beautifully, exactly what I want it to do.  But it costs $30, and I'd rather the pretty new operating system I just bought would work!
    4.  Another clue might be from the airport utility app.  It claims that my airport expresses are no longer supported by airport utility 6.1, and that I should downgrade to airport utility 5.6 to manage those expresses.  Unfortunately, mountain lion is not compatible with airport utility 5.6, so that's a dead end.  I'm not even sure that the answer lies with the airport utility app, because the system can still stream to the expresses, just one at a time.
    Any thoughts?
    System info:
    Model Name:          iMac (21.5 inch, late 2009)
      Model Identifier:          iMac10,1
      Processor Name:          Intel Core 2 Duo
      Processor Speed:          3.06 GHz
      Number of Processors:          1
      Total Number of Cores:          2
      L2 Cache:          3 MB
      Memory:          16 GB
      Bus Speed:          1.07 GHz
      Boot ROM Version:          IM101.00CC.B00
      SMC Version (system):          1.52f9
      System Version:          OS X 10.8 (12A269)

    Update:  10.8.1 fixed it!

  • New to the product - question about validating multiple fields as a group

    I have a static form that I'm building from a word document.  Part of that form requires a person to fill any 3 out 5 text fields.
    Since it looks like scripts are applied on a field by field basis, is it possible to have a script that encompasses multiple fields? 
    Would any script need to be applied to each field in turn?
    Assuming the answer to question 1 is a yes, how would you script it to require x number of fields out of a total of y to have some sort of content in order to validate?
    I'm pretty familiar with JavaScript and am looking at the Scripting reference guides but was hoping for a helping hand to get me there quicker as I'm in a bit of a time crunch - doing 18 forms with validation and database connectivity by January 15 certainly qualifies in my book.
    I would assume you'd do something like this but am unsure of the syntax...
    Get values of each field
    Set a valid counter variable for the number of fields with content
    If field 1 is not empty, increment the valid counter
    (rinse and repeat)
    if the valid counter is less than 3 throw an error message
    Many thanks in advance for any help offiered

    1). Yes, scripting within Livecycle can be for a single field or even static text, images and other artifacts within the PDF. Really anything, within Adobe's reason, when it comes to scripting.
    2). It depends on what you want to do. Things like field validations, calculations and other instances where fields are tied togther really dictate how the script runs.
    3). Fields that have calculations or validations with them work in the same, I believe. So for example I have a PDF that I made that is an Excel-type sheet that contains a few hundred cells and every single one has some type of validation or calculation associated with it. I generally run the calculations/validations from the user inputting the data and then after that the script runs, but again, it really dpeneds on what you are doing and with what, so answering some of your questions are a bit difficult.
    Javascrip/Formcalc are wonderful tools within PDF, but don't forget the Action Builder (Tools -Action Builder). It is a set of preloaded actions that are turn-key. Just select the cells that will have the action and select the result you want from the preloaded list of actions, using those actions can get you very far, and most of all; they are quick to implement without researching code. So for example, you could use the Action Builder to create an action that checks certain fields and if they are null to return a 1 value to a specific numericField (these could be hidden). Then have a "total" numericField (this would be your counter) that adds all of those fields with the 1 in it. Then create another Action Builder for that "total" numericField and if it is less than 3, display a message box that is a warning.

Maybe you are looking for

  • Error when converting time stamp in date time time zone CST  in IC

    Hi Experts, We have recently upgraded from CRM 5.0 to CRM 2007. We are using IC WEB Employee interaction center. so when agent create service ticket in interaction center and close the ticket on same day we are getting an error saying Error when conv

  • PWM signal from Accelerometer by using DIO of PIC-MIO-16E-4

    I am a new beginner to use digital signal acqusition. The accelrometer send the pulse width modualated signal and I need to use DIO line instead of counter. I wonder how I can measure the pulse width, + duty, and -duty.

  • Error when reading data in to ArrayCollection using HTTPService

    Hi, I am trying to read data in to ArrayCollection using HTTPService result property: [Bindable] private var myData:ArrayCollection=new ArrayCollection();    private function result_handler(e:ResultEvent):void         myData = e.result.root.contact;

  • Keyboard not communicating with computer

    When I first boot up my HP All In One, I try to enter my login information but no characters appear. So I restart and am able to log in. But the keyboard stops working. When I hit a key, nothing appears on the screen and I hear kind of a beep (not li

  • IDOC Development

    Hi Gurujis,                I am new to Interfaces concept, But i have good experience in Reporting & Froms. Can somebody sent me some documents on IDOC and INTERFACES end to end development, If possible some case studies. I have two development obejc