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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:33:47+00:00 2026-06-10T11:33:47+00:00

Is something wrong with the construction of this class? I am trying to add

  • 0

Is something wrong with the construction of this class? I am trying to add an instance of it to a JPanel in another class:

public class calculator2 extends JPanel {
     public calculator2() {
         JPanel x = new JPanel();
         x.setLayout(new GridLayout(0,5));

         x.add(new JLabel());
         x.add(new JButton("<<"));
         x.add(new JLabel());
         x.add(new JButton(">>"));
         x.add(new JLabel());
     }
}

This is what I am trying to use it on:

    calculator2 test = new calculator2();
    JPanel panel3 = new JPanel(new BorderLayout());
    panel3.add(test, BorderLayout.SOUTH);

I dont get any type of run time error,it just dosen’t show up. When I put the code from the calculator2 class in the same class I am using in the second portion of code it shows up. Thank you for your consideration.

This is actually just an example, I have a full class with about 25 components using actionlisteners and the like and wanted to add it to a panel using the above method.

  • 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-10T11:33:48+00:00Added an answer on June 10, 2026 at 11:33 am

    Here you are just creating the panel without adding it anywhere to be seen. Try using the parents methods inherited from JPanel instead of creating a new instance of another JPanel in the constructor.

    This will be , just remove the instance called x.

    public class calculator2 extends JPanel {
      public calculator2() {
         super();
         setLayout(new GridLayout(0,5));
    
         add(new JLabel());
         add(new JButton("<<"));
         add(new JLabel());
         add(new JButton(">>"));
         add(new JLabel());
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if there is something wrong with the copy constructor function below? class
I must be doing something wrong here. I'm trying to use Google Analytics to
There must be something wrong. I don't know what? see this on jsfiddle .
In my app, I am trying to set up the camera. My class extends
I am trying to get a vector to store objects of class 'Complex'. This
I'm trying to build a simple Tween class in javascript. The code reads something
I have something like this: class MyBean { @Autowired @Qualifier(jdbcTemplate) @BeanProperty var jdbcTemplate :
Trying to write my first generic class in C#: public class HighScoreList<ScoreType> where ScoreType
There is something wrong with my code. I am teaching myself c# and one
(Maybe I am doing something wrong but) I am getting awful read performance from

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.