Results 1 to 3 of 3
  1. #1
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Rep Power

    Default Set visibility of parent Container

    I have been searching the documentation. What I am trying to do is change the visibility of the parent (JPanel) in this case, on button click. I tried getting the container and then casting to a JComponent but that didn't work. How do I get a hold of the current instance of the parent?


  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Set visibility of parent Container

    Moved from New to Java.

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Tucson, AZ
    Rep Power

    Default Re: Set visibility of parent Container

    Casting should work if the button's parent is actually a JPanel. But you don't need to cast it at all to change its visibility. JButton.getParent() returns a Container, and Container extends Component, which means it has the setVisible(...) method.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Help! set dinamically visibility of panels
    By unkus_nob in forum JavaFX
    Replies: 5
    Last Post: 06-21-2011, 09:06 PM
  2. Help with adding a Container within a Container
    By JoKeR313 in forum New To Java
    Replies: 4
    Last Post: 01-02-2011, 04:59 AM
  3. Java Visibility
    By efozdel in forum New To Java
    Replies: 8
    Last Post: 07-07-2010, 03:36 AM
  4. Replies: 3
    Last Post: 04-21-2009, 11:01 PM
  5. Newbie help on visibility and static final
    By tornado in forum New To Java
    Replies: 3
    Last Post: 11-28-2008, 01:32 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