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 775139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:14:31+00:00 2026-05-14T19:14:31+00:00

JFrame mainFrame = new JFrame(); mainFrame.setSize(100, 100); mainFrame.setBackground(Color.CYAN); mainFrame.setVisible(true); My intent is to create

  • 0
    JFrame mainFrame = new JFrame();
    mainFrame.setSize(100, 100);
    mainFrame.setBackground(Color.CYAN);
    mainFrame.setVisible(true);

My intent is to create a window with a cyan background. What is wrong with this? My window doesn’t get cyan, as I’d expect!

Also, could anyone point out why I seem to have all the colors in duplicate (there’s a Color.CYAN and a Color.cyan). Is there any difference at all between the two? Maybe the older one was a constant from before there were enums in Java and the second one is from the Enum?

Thanks

  • 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-14T19:14:32+00:00Added an answer on May 14, 2026 at 7:14 pm

    Why is the windows not cyan as expected?

    The issue here is that the area where the contents of the JFrame is being displayed is actually the “content pane”, and not contents of the JFrame itself.

    Therefore, the following line:

    mainFrame.setBackground(Color.CYAN);
    

    Is changing the color of the JFrame, but that is actually not the part which is immediately visible when the JFrame is displayed.

    What is needed is to change the color of what is called the “content pane* (please refer to How to Use Root Panes for an illustration), by changing the above line to the following:

    mainFrame.getContentPane().setBackground(Color.CYAN);
    

    Using Frames in Swing could be surprisingly unintuitive at the beginning, so I would strongly recommend taking a look at the resources I’ve listed at the bottom of this answer.

    Is there a difference between Color.CYAN and Color.cyan?

    No, there is no difference between the two — they are both constants in the Color class which are Color objects themselves. The only difference is in the names of the constants.

    The constants with lowercase names were introduced when the Color class was introduced (which appears to be JDK 1.0, as there is no “Since” notation in the Java API Specification for the Color class), and the uppercase names were added later on in JDK 1.4.

    Probably the addition of the uppercase named constants were added to make the constant names in the Color class consistent with the Code Conventions for the Java Programming Language which in Section 9: Naming Conventions state that constants should be in all uppercase letters.

    Resources

    For more information on how to use Frames, the following resources from The Java Tutorials would be of interest:

    • How to Make Frames – information on general about how to make Frames.

    • How to Use Root Panes – more specific information about panes, including an illustration of how the different panes relate to each other.

    • Using Top-Level Containers
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I make a JFrame like this public static void main(String[] args) { new
I have a window (derived from JFrame) and I want to disable the close
I have a JFrame with a menu bar and a canvas covering all the
I'm using a JFrame in which the CENTER portion of the BorderLayout is occupied
I have a JFrame that contains a display JPanel with JTextField and a control
I have a JFrame. This JFrame contains a JButton. I click the JButton and
My current application has a JFrame with about 15 actions stored as fields within
My current problem is that I have a JFrame with a 2x2 GridLayout. And
I'm trying to implement a KeyListener for my JFrame . On the constructor, I'm
This one's a tough one - I have a JFrame that generates JTextFields. When

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.