Results 1 to 6 of 6
  1. #1
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default Remove A JPanel From A Separate Class

    Hello, I have been trying to get this to work for the last hour or so and it is driving
    me crazy! I have build a program that has a main JFrame and then 2 separate
    JPanels added on to the JFrame. I need one of the JPanels to remove the other one when a button is hit. Thanks for your help.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Remove A JPanel From A Separate Class

    Have you tried calling the remove method?

  3. #3
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default Re: Remove A JPanel From A Separate Class

    Quote Originally Posted by Norm View Post
    Have you tried calling the remove method?
    Yes here is what I did
    ListPane p = new ListPane();
    Gui g = new Gui();
    p.list.setVisible(false);
    p.repaint();
    g.repaint();

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

    Default Re: Remove A JPanel From A Separate Class

    Quote Originally Posted by anthropamorphic View Post
    Yes here is what I did
    ListPane p = new ListPane();
    Gui g = new Gui();
    p.list.setVisible(false);
    p.repaint();
    g.repaint();
    I'm not sure how this code you've posted helps us to understand just what you current problem is other than I fear that you may be calling methods on the wrong object, but I cannot say for sure based on the information at hand.

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: Remove A JPanel From A Separate Class

    The basic code or removing (or adding) a component should be:

    Java Code:
    panel.remove(...);
    panel.revalidate();
    panel.repaint();

  6. #6
    just_in_deed is offline Member
    Join Date
    Aug 2010
    Posts
    25
    Rep Power
    0

    Default Re: Remove A JPanel From A Separate Class

    this is interesting but the code you provided is not sufficient to understand how your program behaves

Similar Threads

  1. How do i remove images from a Jpanel?
    By rajkobie in forum New To Java
    Replies: 2
    Last Post: 05-12-2011, 03:44 PM
  2. JPanel add/remove in a JFrame
    By Aldane in forum AWT / Swing
    Replies: 2
    Last Post: 03-28-2011, 08:28 PM
  3. how to separate this code in another class
    By Jhovarie in forum AWT / Swing
    Replies: 5
    Last Post: 03-01-2011, 06:08 PM
  4. Separate file for main and class
    By eel in forum New To Java
    Replies: 12
    Last Post: 09-18-2010, 09:24 AM
  5. how to remove all component in container(Jpanel)
    By SaYuNaRa in forum New To Java
    Replies: 3
    Last Post: 04-17-2008, 05:22 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
  •