Results 1 to 3 of 3
  1. #1
    warchieflll is offline Member
    Join Date
    Dec 2010
    Rep Power

    Question add(component) gives 2 components?

    Heey all!

    I try to add one component to a arraylist. When I check the arraylist, it says there are two components in... (I also see two imgIcons)

    Java Code:
    	public void mouseClicked(MouseEvent e)
    		randomBoolean = booleanGenerator.nextBoolean();
    		huidigDier = new Dier(dierSoort, 50, randomBoolean);
    		huidigDier.setBounds(e.getX(), e.getY(), 50, 50);
    Java Code:
    	public Dier (String soort, int grootte, boolean vrouwtje)
    		this.soort = soort;
    		this.grootte = grootte;
    		this.vrouwtje = vrouwtje;
    	public void maakIcoon()
    		dierIcoon = new ImageIcon(Dier.class.getResource("/pics/" + soort + ".png"));
    		imgLabel = new JLabel(dierIcoon);
    		imgLabel.setBounds(0, 0, grootte, grootte);
    Any idea's?

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    I see that your code is dynamically adding components, but it isn't clear that you are invalidating the container, so it's possible to get unexpected behavior in the GUI.

    The other possibility is that 'mouseClicked' is getting called more than once. Is 'addMouseListener' being called multiple times?

  3. #3
    warchieflll is offline Member
    Join Date
    Dec 2010
    Rep Power


    Eehm... well, I've got more mouseListeners (so in, and in (the upper one)). In the mouseClicked is empty, so I'm not sure if it activated the one in

    The addMouseListener is only called once...


    You are right!! I've had: public class Kooi extends Verblijf, and in the class Kooi a addMouseListener, and also in the class Verblijf...! Stupid I didn't notice...!

    Thank ya very much!
    Last edited by warchieflll; 01-31-2011 at 04:13 PM.

Similar Threads

  1. Table for component
    By VojtechSejkora in forum AWT / Swing
    Replies: 8
    Last Post: 11-28-2010, 01:23 AM
  2. Find a component by its name
    By uiproject in forum AWT / Swing
    Replies: 3
    Last Post: 11-27-2010, 05:09 PM
  3. Component not updating??!!
    By XmisterIS in forum New To Java
    Replies: 5
    Last Post: 09-03-2010, 12:25 PM
  4. Component to use ?
    By pbaudru in forum AWT / Swing
    Replies: 2
    Last Post: 02-17-2010, 10:55 AM
  5. add component to component
    By Omarero in forum New To Java
    Replies: 7
    Last Post: 05-17-2009, 03:39 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