CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2000
    Location
    Kaysville, UT
    Posts
    228

    Need help redrawing/sizing JPanels

    Here's the situation:

    I have a JPanel (call it mainPane) contained within a JFrame (call it mainFrame). It is added via

    mainFrame.getContentPane().add(mainPane);




    To mainPane I am adding and removing other JPanels. What I would like to do is that whenever a JPanel contained in mainPane is removed or set invisible the window shrinks to show the deletion, so that the space taken up by the pane is no longer there. Right now whenever a pane is set invisible it still takes up room, and so the window doesn't shrink. I'm left with these big empty spaces.

    Any ideas would be most appreciated.

    Thanks!


    "There's nothing more dangerous than a resourceful idiot." ---Dilbert
    BWAHAHAHAHAHAHA! ---Murray

  2. #2
    Join Date
    Sep 2000
    Location
    Melbourne --> Australia
    Posts
    68

    Re: Need help redrawing/sizing JPanels

    Hi there
    I think that you arent re setting the size and
    then validating.
    This is a way you can do it.
    Set up two methods, add() and remove() which
    both have JPanels for method parameter's, and
    then call either one ie:
    add(nameOfJPanel);
    or
    or remove(nameOfJPanel);

    The add() method could look like this:
    void add(JPanel jp){
    getContentPane().add(jp);
    setSize(400,400);
    validate();
    }


    and the remove method could look like this :
    void remove(JPanel jp){
    getContentPane().remove(jp);
    setSize(0,0);
    validate();
    }


    Good Luck
    Phill.





Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured