Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:25:22+00:00 2026-06-15T19:25:22+00:00

getContentPane().setLayout(new CardLayout()); CardLayout x = (CardLayout) getLayout(); I’m using Netbeans and in Design manager

  • 0
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:25:23+00:00Added an answer on June 15, 2026 at 7:25 pm

    You can use:

    CardLayout x = (CardLayout) getContentPane().getLayout();
    

    Similarly to switch card panels you can use:

    x.show(getContentPane(), "card2");
    

    This is not an issue if you simply use a separate JPanel as the ‘card’ container plus you get the added benefit of using the JFrame BorderLayout should you wish to add navigation buttons, say in the BorderLayout.SOUTH location.

    Essential reading for using CardLayout

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm Using Camick's ListTableModel and RowTableModel from here http://tips4java.wordpress.com/2009/03/12/table-from-database/ However, the JTable is not
I have Ex1 below: main(String args[]) { JFrame frame = new JFrame(Title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton
I'm using a cardlayout and I want to make it so that the first
I want to call outer class' method getContentPane() from inner Action class. I don't
Here my issue, I have 2 Jframe, one for controlling and one for displaying
I am new to java swing. I have pasted my code below for your
I am coding a gui in SWING: JLabel tLabel1 = new JLabel(Name: ); JFormattedTextField
I'm working on a small Java applet, very much new to this programming thing.
When I create my GUI I use a cardlayout to hold my different panels
i am new to java GUI programming. i am adding a JEditor pane (with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.