Results 1 to 3 of 3
- 01-31-2011, 02:54 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 55
- Rep Power
- 0
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); dierenLijst.add(huidigDier); add(huidigDier); huidigDier.setBounds(e.getX(), e.getY(), 50, 50); }Any idea's?Java Code:public Dier (String soort, int grootte, boolean vrouwtje) { setOpaque(false); addMouseListener(this); this.soort = soort; this.grootte = grootte; this.vrouwtje = vrouwtje; maakIcoon(); } public void maakIcoon() { dierIcoon = new ImageIcon(Dier.class.getResource("/pics/" + soort + ".png")); imgLabel = new JLabel(dierIcoon); imgLabel.setBounds(0, 0, grootte, grootte); add(imgLabel); }
- 01-31-2011, 03:03 PM #2
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
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?
- 01-31-2011, 03:08 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 55
- Rep Power
- 0
Eehm... well, I've got more mouseListeners (so in Dier.java, and in Verblijf.java (the upper one)). In Dier.java the mouseClicked is empty, so I'm not sure if it activated the one in Verblijf.java?
The addMouseListener is only called once...
Edit:
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 03:13 PM.
Similar Threads
-
Table for component
By VojtechSejkora in forum AWT / SwingReplies: 8Last Post: 11-28-2010, 12:23 AM -
Find a component by its name
By uiproject in forum AWT / SwingReplies: 3Last Post: 11-27-2010, 04:09 PM -
Component not updating??!!
By XmisterIS in forum New To JavaReplies: 5Last Post: 09-03-2010, 11:25 AM -
Component to use ?
By pbaudru in forum AWT / SwingReplies: 2Last Post: 02-17-2010, 09:55 AM -
add component to component
By Omarero in forum New To JavaReplies: 7Last Post: 05-17-2009, 02:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks