Frage

i have a jPanel containing 3 menus--lets call it MenuPanel i place it on the top of my jFrame (border_layout top). 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

War es hilfreich?

Lösung

Simple solution: use a CardLayout to help you swap JPanels.

  • Place a JPanel that uses CardLayout in the BorderLayout.SOUTH position, say called cardHolderPanel.
  • Add the three "card" JPanels into the cardHolderPanel using unique String constants.
  • Swap the cards by calling show(cardHolderPanel, APPROPRIATE_STRING_CONSTANT) on your CardLayout.

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top