Creating a GUI with multiple panels and one frame

泄露秘密 提交于 2019-12-05 07:21:22

问题


I am trying to create a simple GUI. I have a menu bar that is filled with various JMenuItems. Each menu item should link to a different "window". Currently, I am thinking the best way to do this is to create a single frame, and create various JPanels. My ActionListeners will toggle visibility of the different panels, and only one panel should be visible at a time. Is this the best way to go about the task? Or is there a better workaround.


回答1:


Yes, the best way is to use a CardLayout of which there's a great tutorial (please see the link), and many examples online including in this very forum, several of which I've written, including:

  • Java CardLayout Main Menu Problem
  • Change size of JPanel using CardLayout
  • Java CardLayout JPanel moves up, when second JPanel added
  • Java swing; How to toggle panel's visibility?
  • Clear components of JFrame and add new componets on the same JFrame
  • gui multiple frames switch
  • JLabel displaying countdown, java



回答2:


JTabbedPane is already implemented for you!
JTabbedPane's tutorial.



来源:https://stackoverflow.com/questions/8275728/creating-a-gui-with-multiple-panels-and-one-frame

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