?
Solved

adding container's parent to itself

Posted on 2006-07-23
9
Medium Priority
?
1,775 Views
Last Modified: 2012-08-13

hello there,

i am trying to insert many jbuttons into a jpanel.but i get this error.can anyone help me solve this

java.lang.IllegalArgumentException: adding container's parent to itself

private JPanel createTerminalPanel()
    {         
          JPanel pKey = new JPanel(new GridLayout());
          
          
          innerCardPanel = new JPanel(new CardLayout());
          
          pKey.add(new JButton("C"));
        pKey.add(new JButton("MR"));
        pKey.add(new JButton("M-"));
        pKey.add(new JButton("M+"));
        pKey.add(new JButton("7"));
        pKey.add(new JButton("8"));
        pKey.add(new JButton("9"));
        pKey.add(new JButton("/"));
        pKey.add(new JButton("4"));
        pKey.add(new JButton("5"));
        pKey.add(new JButton("6"));
        pKey.add(new JButton("*"));
        pKey.add(new JButton("1"));
        pKey.add(new JButton("2"));
        pKey.add(new JButton("3"));
        pKey.add(new JButton("-"));
        pKey.add(new JButton("0"));
        pKey.add(new JButton("."));
        pKey.add(new JButton("="));
        pKey.add(new JButton("+"));
       
        innerCardPanel.add(pKey, MDF_PANEL);
       
        pKey.add(innerCardPanel, BorderLayout.CENTER);
          
          return pKey;
    }
0
Comment
Question by:zolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 500 total points
ID: 17162830
> pKey.add(innerCardPanel, BorderLayout.CENTER);

i think you don't need this
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17162832
>>innerCardPanel.add(pKey, MDF_PANEL);

should be

innerCardPanel.add(pKey, "Calculator");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17162833
Also, you don't want to add the card panel to the grid layout
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17162834
(which you're doing here)

>>pKey.add(innerCardPanel, BorderLayout.CENTER);
0
 

Author Comment

by:zolf
ID: 17162836


can you give me an example where i can add many buttons into a jpanel.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17162838
That bit's OK. You need to determine what you want to do with the CardLayout. What's its purpose? At the moment the reference to it is lost
0
 

Author Comment

by:zolf
ID: 17162867

i use the cardlayout to switch between two views.my application which i am working on is very complicated and vast.
i managed to get some buttons on a panel and show.but i have got other error which i have to look into.
thanks anyway.
0
 

Author Comment

by:zolf
ID: 17162871

that is the reason i cannot paste all the code in here.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17162878
:-)

OK. If you want to add that calculator panel to a CardLayout, you can pass a reference to the CardLayout into the method, or just add the return value directly to the CardLayout
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question