How to switch JPanel cards when a JMenu is clicked

邮差的信 提交于 2020-07-20 06:32:33

问题


I'm building an application using Netbeans where I have to switch from one JPanel to another when a specific JMenu is clicked.

I have tried to use the following code but it won't work.

MainPane is the main panel, NewpatientPane is the panel to switch to while card2 is the card name for the NewpatientPane.

Any help will be appreciated.

public void pharmacyMenuActionPerformed(java.awt.event.ActionEvent evt){
     CardLayout card = (CardLayout)MainPane.getLayout();
     card.show(Mainpane, "card2");
     NewpatientPane.setVisible(true);
}

来源:https://stackoverflow.com/questions/62969737/how-to-switch-jpanel-cards-when-a-jmenu-is-clicked

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