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

    Question Label not visible on panel

    Greetings all!

    I've got a label, which is not visible on a panel??

    Java Code:
    	  public void mouseClicked(MouseEvent e)
    	  {
    		  add(new JLabel ("Grootte van de bal: "));
    		  System.out.println("geklikt op een verblijf met als diersoort ..." + dierSoort);
    	  }
    When i click on the panel, the tekst 'geklikt op een verblijf met als diersoort... ' showed up, but the label isn't visible...?
    Last edited by warchieflll; 01-29-2011 at 01:54 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    If you ever add a component to a container, you need to revalidate that container after the changes have been made. This is done by calling revalidate() on the container (assuming that it derives from JComponent). Sometimes, especially if you also have to remove components, you must call repaint() on the container as well.

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

    Default

    Hmm... the panel is showing now indeed something, but not what I want yet... I draw a panel (with dragging). Now if I click the mouse with the revalidate(); code, the panel takes a different size...

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

    Default

    Ah, I see it works with setBounds... thanks for you help!! Ur great :)

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I think that you are having issues with your container's layout manager. Which manager are you using? Also, please look at the link in my signature below on creating an SSCCE so that we can run and test your code, alter it, and better help you solve your problem.

Similar Threads

  1. panel on a panel not visible
    By warchieflll in forum Advanced Java
    Replies: 2
    Last Post: 01-29-2011, 09:29 PM
  2. Add panel to parent panel
    By LovJava in forum AWT / Swing
    Replies: 10
    Last Post: 09-02-2010, 09:43 PM
  3. Replies: 4
    Last Post: 08-11-2010, 01:47 PM
  4. Adding a panel to a panel
    By rclausing in forum New To Java
    Replies: 7
    Last Post: 02-02-2010, 06:56 AM
  5. JTextField not visible?
    By McChill in forum New To Java
    Replies: 2
    Last Post: 05-20-2009, 01:17 AM

Posting Permissions

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