I have a jInternalPane
within a jDesktopPane
. The jDesktopPane
is within a jPanel
that has the BorderLayout
layout.
In my internal pane, I am trying to programatically switch cards. I have the following, relevant piece of code that breaks:
public void switchCards() {
CardLayout cl = (CardLayout)(internalFrame1.getLayout());
cl.show(internalFrame1, "card1"); //Where card1 is a jPanel
}
However, in the error trace, I can see the following:
javax.swing.plaf.basic.BasicInternalFrameUI$Handler cannot be cast to java.awt.CardLayout
.
Can someone please point me in the right direction to properly handle this error? I would love to learn how to do it!
Many thanks in advance.
You would use a CardLayout on the content pane of the JInternalFrame, not the internal frame itself.
You can just set the layout of the content pane:
Container contentPane = internalFrame.getContentPane();
contentPane.setLayout( new CardLayout() );
contentPane.add(panel1, "Card1");
contentPane.add(panel2, "Card2");
Then your switchCards() method would be:
Container contentPane = internalFrame.getContentPane();
CardLayout cl = (CardLayout)(contentPane.getLayout());
cl.show(contentPane, "card1"); //Where card1 is a jPanel
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.