show one panel after button is clicked and other panel when second button is clicked in the same frame

这一生的挚爱 提交于 2019-12-11 08:22:38

问题


I am creating a Swing based application , which actually consist of two buttons as shown below -

now what i want is when first button is clicked it must perform a action like showing a panel containing label, textfields , and some buttons in the same frame as shown below -

and when second button is clicked it will show another panel in the same frame as shown below ..

the thing is i am not understanding how to make this interface in action by providing event handler and action listener .. So please letme me know how can i archive this . Any help would be appreciated .. Thanks


回答1:


There are 2 approaches.

  1. CardLayout based.
    Create all the panels (empty, panel with fields, panel with list) and add them in a container with CardLayout (the empty one is default). On click buttons swap visible cards (panels) showing necessary one.

  2. Recreation based.
    On click button create a new panel with new content. Remove the old one from container and add the newly created pane. After then call:

    container.revalidate();
    container.repaint();
    


来源:https://stackoverflow.com/questions/21823610/show-one-panel-after-button-is-clicked-and-other-panel-when-second-button-is-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!