getContentPane().setLayout(new CardLayout());
CardLayout x = (CardLayout) getLayout();
I’m using Netbeans and in Design manager I chosed my JFrame contents as CardLayout. However I cannot make it work so far. I set the above code after the initComponenets call and still I have this error:
java.awt.BorderLayout cannot be cast to java.awt.CardLayout
Somehow I have BorderLayout instead of CardLayout. How is it possible? I’ve just set layout as CardLayout. PS: my class extends javax.swing.JFrame.
You can use:
Similarly to switch card panels you can use:
This is not an issue if you simply use a separate
JPanelas the ‘card’ container plus you get the added benefit of using theJFrameBorderLayoutshould you wish to add navigation buttons, say in theBorderLayout.SOUTHlocation.Essential reading for using CardLayout