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

    Default panel on a panel not visible

    Greetings everyone!

    I've made a simple zoo, where I got:

    - a startup class
    - a 'zoo' class (main panel)
    - a 'cage' class (panel on panel)
    - a 'staying' class (a cage = a staying place, so staying = super class)
    - a 'animal' class (the animal himself)

    Now, when I start the app, I could drag the mouse, and a cage (what is a staying), appears. Now, I want to click that cage, and a animal appear, but it woudn't work:

    In the zoo drag-function:
    Java Code:
    	  public void mouseDragged(MouseEvent e)
    	  {    
    		  if (!dragged)
    		  {
    		      Kooi kooi = new Kooi();
    		      add(kooi);
    		      huidigeKooi = kooi;
    		      dragged = true;
    		  }
    	      huidigeKooi.setKooi(startX, startY, e.getX(), e.getY());
    	      repaint();
    	  }
    in the cage:
    Java Code:
    public class Kooi extends Verblijf
    in the staying (system.out.prinln appear, so that works)
    Java Code:
    	  public void mouseClicked(MouseEvent e)
    	  {
    		  System.out.println("geklikt op een verblijf met als diersoort ..." + dierSoort);
    		  huidigDier = new Dier(dierSoort, 50, randomBoolean);
    		  dierenLijst.add(huidigDier);
    		  add(huidigDier);
    		  huidigDier.setVisible(true);
    		  repaint();
    	  }
    in the animal class:

    Java Code:
    	public Dier (String soort, int grootte, boolean vrouwtje)
    	{
    		this.soort = soort;
    		this.grootte = grootte;
    		this.vrouwtje = vrouwtje;
    		
    		int MARGE = 0; // afstand vanaf de bovenrand
    		int KNOP_BREEDTE = 50; // breedte in pixels
    		int KNOP_HOOGTE = 50; // breedte in pixels
    		int KNOP_AFSTAND = 0; // verschuiving
    		int X_LOCATIE = 0; // linkerkant van de knop
    		
    	    JLabel imgLabel;
    		dierIcoon = new ImageIcon("java_plaatjes_verkleind/" + soort + ".jpg");
    		imgLabel = new JLabel("aaaaaaaaaaaaaaaaaaaaaaaaa" + dierIcoon);
    		imgLabel.setBounds(X_LOCATIE, KNOP_AFSTAND + MARGE, KNOP_BREEDTE, KNOP_HOOGTE);
    		add(imgLabel);
    		
    		repaint();
    	}
    Thanks in advance!

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    You are adding components dynamically after their container has been realized. Call re-validate on the added component (JPanel in this case), or validate on the container.

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

Similar Threads

  1. Add panel to parent panel
    By LovJava in forum AWT / Swing
    Replies: 10
    Last Post: 09-02-2010, 08:43 PM
  2. Panel in a panel?
    By pahiker in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2010, 11:42 AM
  3. Adding a panel to a panel
    By rclausing in forum New To Java
    Replies: 7
    Last Post: 02-02-2010, 05:56 AM
  4. How to output to panel as a .gif
    By Teh Brian in forum New To Java
    Replies: 1
    Last Post: 03-13-2009, 05:26 PM
  5. panel positioning
    By shwein in forum New To Java
    Replies: 4
    Last Post: 09-09-2008, 05:15 PM

Tags for this Thread

Posting Permissions

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