简体   繁体   English

java-如何根据用户点击次数替换jPanel

[英]java - how to replace a jPanel based on user clicks

i have a jPanel containing 3 menus--lets call it MenuPanel i place it on the top of my jFrame (border_layout top). 我有一个包含3个菜单的jPanel,可以将其命名为MenuPanel,将其放在我的jFrame的顶部(border_layout顶部)。 i have also 3 jPanels (PanelOne, PanelTwo, PanelThree) and i want it to be showed on the bottom of the jFrame (border_layout bottom) based on the menu that the user choose 我也有3个jPanels(PanelOne,PanelTwo,PanelThree),我希望根据用户选择的菜单将其显示在jFrame的底部(border_layout底部)

Simple solution: use a CardLayout to help you swap JPanels. 简单的解决方案:使用CardLayout帮助您交换JPanels。

  • Place a JPanel that uses CardLayout in the BorderLayout.SOUTH position, say called cardHolderPanel. 将使用CardLayout的JPanel放在BorderLayout.SOUTH位置,例如,称为cardHolderPanel。
  • Add the three "card" JPanels into the cardHolderPanel using unique String constants. 使用唯一的String常量将三个“ card” JPanel添加到cardHolderPanel中。
  • Swap the cards by calling show(cardHolderPanel, APPROPRIATE_STRING_CONSTANT) on your CardLayout. 通过在CardLayout上调用show(cardHolderPanel, APPROPRIATE_STRING_CONSTANT)来交换卡片。

Tutorial: http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html 教程: http//docs.oracle.com/javase/tutorial/uiswing/layout/card.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM