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

  • SEARCH
  • Home
  • 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 7063519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:43:23+00:00 2026-05-28T04:43:23+00:00

I am learning Java (slowly) from the ground up, but every now and again

  • 0

I am learning Java (slowly) from the ground up, but every now and again I peak at some “real” code and I found something that confused me.

The following line and ones like it:

JPanel panel = (JPanel) container.getContentPane();

My question is what is happening between (JPanel) and container.getContentPane()? Its not like they are being multiplied right?

I know this is a basic part of the language and as I continue learning I’ll get to this part, but I got really curious and wanted to know what it was right away. I didn’t really know what to google to get the answer.

  • 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-05-28T04:43:24+00:00Added an answer on May 28, 2026 at 4:43 am

    Its not like they are being multiplied right?

    No. It means “get this thing and treat it as a JPanel.” It’s called type casting and that syntax is used in C++, C# and many other languages.

    You have to make sure that the way that the classes are related to each other allows for casting. For example, this wouldn’t work:

    JPanel p = new JPanel();
    JComponent c = (JComponent)p;
    JButton b = (JButton)c;
    

    JPanel is a JComponent and so is JButton, but JButton does not descend from JPanel thus you cannot cast between these objects. You can also cast from a child back to a parent, such as from JSpinner.DefaultEditor back to JPanel, but not from JPanel to JSpinner.DefaultEditor.

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

Sidebar

Related Questions

When I was learning Java coming from a background of some 20 years of
I'm learning Java right now but I'm wondering if there is a hierarchy of
I recently started learning Java and found it very strange that every Java public
I'm learning Java by reading the online Java book, but im finding it hard
Learning java server technologies, trying to clarify some things. There are few technologies that
I'm learning java and I have made simple program that simply reads value from
I am learning Java, now working with arrays. I am doing an excercise where
Well..I am learning java now and I am curious to know will this yield
I just started learning Java and I encountered some problems with the tag in
I am learning java, and studying the following example from sun.com. import java.io.*; import

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.