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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:29:39+00:00 2026-05-25T02:29:39+00:00

I have a problem with JFrame and the key word this. When I use

  • 0

I have a problem with JFrame and the key word “this”. When I use frame.getContentPane, components don’t show up unless I replace frame with “this”. It seems getContentPane doesn’t get the JFrame content pane, it gets something else I don’t know what it is. I’m afraid I have two different JFrame components even though I declared only one. Can anybody explain this problem?
This is my code:

public class Form1 extends JFrame
{
    private static final long serialVersionUID = 1L;
    JFrame frame = new JFrame("TableLayout");
    Container content = frame.getContentPane();//this doesn't work unless I replace "frame" with the key word "this"///
public Form1 ()//constructor
{
    String label[] = {"Top", "Bottom", "Add", "Delete", "Center", "Overlap"};
     double border = 5;
     double size[][] =
      {{border, 0.20, border, TableLayout.FILL, border, 0.80, border},  // Columns
       {border, 0.15, border, TableLayout.FILL, border, 0.10, border}}; // Rows  
     JButton button[] = new JButton[label.length];
     for (int i = 0; i < label.length; i++)
     {
         button[i] = new JButton(label[i]);
     }
     content.add (button[0], "1, 1, 5, 1"); // Top (row,column)
     content.add (button[1], " 1, 5, 5, 5"); // Bottom
     content.add ((button[2], "1, 3      "); // Left
     content.add (button[3],"5, 3,      "); // Right
     this.pack();
    }
}
  • 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-25T02:29:39+00:00Added an answer on May 25, 2026 at 2:29 am
    public class Form1 extends JFrame
    {
        private static final long serialVersionUID = 1L;
        JFrame frame = new JFrame("TableLayout");
    

    Your class is a frame and also has a Frame attribute named frame. Of course there are two frames!

    Change this..

    public class Form1 extends JFrame
    {
        private static final long serialVersionUID = 1L;
        JFrame frame = new JFrame("TableLayout");
        Container content = frame.getContentPane();//this doesn't work unless I replace "frame" with the key word "this"///
    public Form1 ()//constructor
    {
    

    To something more like (definite answers come with an SSCCE in the question)..

    public class Form1 extends JFrame
    {
        private static final long serialVersionUID = 1L;
        Container content;
    
    public Form1 ()//constructor
    {
        super("TableLayout");
        content = getContentPane();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this logical problem regarding on how to pass value from one JFrame
I have this Java JFrame class, in which I want to use a boxlayout,
i have a transparent JFrame AWTUtilities.setWindowOpaque(this, false); I have a problem when resizing the
This is the problem, I have a class MainWindow that extends JFrame in one
My current problem is that I have a JFrame with a 2x2 GridLayout. And
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a problem with my two JList components. I created and placed on
I have this problem bothering me for days. I'm making a special paint program.
Hi I have a small problem. I have a JFrame with a JComponent I
I have a problem. I used Gridbaglayout in my JFrame. One of the component

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.