简体   繁体   English

如何获得jInternalPane的卡布局?

[英]How can I get the card layout of an jInternalPane?

I have a jInternalPane within a jDesktopPane . 我在jInternalPane中有一个jDesktopPane The jDesktopPane is within a jPanel that has the BorderLayout layout. jDesktopPane位于具有BorderLayout布局的jPanel中。

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 . 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. 您将在JInternalFrame的内容窗格上使用CardLayout,而不是内部框架本身。

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: 然后,您的switchCards()方法将是:

Container contentPane = internalFrame.getContentPane();
CardLayout cl = (CardLayout)(contentPane.getLayout());
cl.show(contentPane, "card1"); //Where card1 is a jPanel

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

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