CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    5

    Help on removing awt components

    Hi,
    I have a class that extends Frame. I have two panels in it - one that contains two buttons ("add" and "remove") and the other panel is empty and has FlowLayout as it's layout manager. The panels are added to the Frame using BorderLayout.

    I wrote the eventhandler for the "add" button to add a new button to the initially empty panel, each time the "add" button is clicked. I am calling validate() and pack() for the container after adding the new button. Also, I wrote the handler for the "remove" button to remove the last added button. I have got two problems.

    1. When I keep adding the buttons, I can't control the size of the Frame and have the new buttons wrapped around, instead the Frame is becoming wider and wider. I tried using setSize but it doesn't work.

    2. Component.remove() is not working. I am doing this from an inner class which listens to the "remove" button. I am calling validate() on the container after calling remove. But the button is not removed.

    Can anyone help.

    thanx in advance
    JAIKISH


  2. #2
    Join Date
    May 1999
    Posts
    93

    Re: Help on removing awt components

    1. If you don't want the frame to resize, don't call pack().
    2. You have to call Container.remove(Component);


  3. #3
    Join Date
    Apr 1999
    Posts
    5

    Re: Help on removing awt components

    Thanx for the suggestions, I want the Frame to resize only in the vertical direction when the buttons spill over to the next line. How can I do that? Right now, I am adding the components and just saying pack() so that it resizes on its own. From your suggestion, I think I will have to manually resize the Frame each time I add a new button to acheive my goal. If so how can I know whether the button has jumped to the next line ? However, I tried resizing the Frame with a hardcoded size and without calling pack, but to no avail. It refused to resize and the new button is visible only if I forcefully resize the Frame while using.

    Now for the remove part of the problem, I am using Container.remove(Component), but it is not working. What can be the problem ? I added a containerListener to the panel containing the buttons and tested. componentRemoved event is not triggered at all. But I am able to remove the button by calling removeNotify, which destroys the peer component (it is not supposed to be called directly according to the documentation)

    thanx
    JAIKISH


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