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

    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?

    Thanks

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    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.

    db
    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
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    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, 10: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, 05:59 AM
  3. Java Visibility
    By efozdel in forum New To Java
    Replies: 8
    Last Post: 07-07-2010, 04:36 AM
  4. Replies: 3
    Last Post: 04-22-2009, 12:01 AM
  5. Newbie help on visibility and static final
    By tornado in forum New To Java
    Replies: 3
    Last Post: 11-28-2008, 02: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
  •