创建具有多个面板和一帧的GUI [英] Creating a GUI with multiple panels and one frame

查看:122
本文介绍了创建具有多个面板和一帧的GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的GUI。我有一个充满各种JMenuItems菜单栏。每个菜单项应该链接到一个不同的窗口。目前,我想做到这一点的最好办法是建立一个单一的框架,并建立各种JPanels。我的ActionListeners将切换不同的面板的知名度,只有一个面板应在同一时间可见。这是去了解任务的最佳方法是什么?或者,是否有更好的解决方法。

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.

推荐答案

是的,最好的办法是使用的 CardLayout 其中有一个伟大的教程(请参阅链接),以及许多在线的例子,包括在这个论坛上,其中一些我写的,其中包括:

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

这篇关于创建具有多个面板和一帧的GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆