Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

how do you add or remove JPanel in Jframe during runtime(Java Question)?

I have three classes JFame,JPanel,LeftPane and ActionListener class.I have a button in LeftPane and i am trying to change the visibility or add or remove the JPanel from JFrame when the button is clicked. I have implemented the ActionListener to do this and then i wrote frame.validate to bring changes in Frame during runtime, but it doesnt work

Can anyone give me a small example how to do so or is there sourse code online please send me link

Thanks alot

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    You may be able to do 1 of 2 things.

    1) get the content pane and do validate on that.

    getContentPane().validate();

    2) set the frame to invisible than visible

    setVisible(false);

    setVisible(true);

Still have questions? Get your answers by asking now.