如何用Java中的另一个JPanel替换两个JPanel中的一个? [英] How can I replace one of two JPanels with another JPanel in Java?

查看:594
本文介绍了如何用Java中的另一个JPanel替换两个JPanel中的一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为欢迎屏幕设计了一个界面,其中一个JFrame包含两个JPanel(右边是JPanel1,左边是JPanel2)。左侧的按钮用于切换JPanel1中的面板。我想按一个按钮将JPanel1内容替换为另一个JPanel,但我不知道如何。请帮忙。

I designed an interface for the welcome screen with one JFrame included two JPanels (JPanel1 on right and JPanel2 on left). The buttons on the left is to switch the Panels in JPanel1. I want to press on a button to replace JPanel1 content with another JPanel but I don`t know how. Please help.

推荐答案

我找到的最佳答案是我只会创建一个JFrame,并且会让一个大的JPanel包括两个JPanels (JPanelLeft包括按钮和JPanelRight包含按钮的功能)然后我将为每个JButton复制主JPanel。
当我按下任何按钮时,我会(JFrame.getContentPane.removeAll)删除旧的JPanel(JFrame.getContentPane.Add(NewJPanel)。

The best answer I found is that I will create one JFrame only and gonna make one big JPanel include two JPanels (JPanelLeft include the buttons and JPanelRight include what the button do) then I will copy the main JPanel for each JButton. When I press on any button I will do (JFrame.getContentPane.removeAll) to remove the old JPanel then (JFrame.getContentPane.Add(NewJPanel).

这对我有用,并保持我想要的设计。感谢每一个人。

This works for me and keep my design as I Want. Thanks for every body.

这篇关于如何用Java中的另一个JPanel替换两个JPanel中的一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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