This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

container's containment

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this statement from sun website. I couldn't understand. could someone explain it,please.

Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the first container and then added to the second.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a specific component can only be in one place at a time.

run this and the button will end up added to the final panel only


now move the creation of the button to inside the loop and it works OK,
because each button (same name) is a separate button
 
krishna prasad gunasekaran
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why is this happening to components that are different from each other.
This is my code excerpts.

public static void showFrame()
{
JFrame frame=new JFrame("Swing Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JMenuBar menu=new JMenuBar();
menu.setOpaque(true);
menu.setBackground(new Color(154,165,127));
menu.setPreferredSize(new Dimension(200, 20));

JLabel label=new JLabel();
label.setOpaque(true);
label.setBackground(new Color(248, 213, 131));
label.setPreferredSize(new Dimension(200, 180));

JButton btn = new JButton("OK");
JPanel panel=new JPanel();
panel.setPreferredSize(new Dimension(100,50));
panel.add(btn);


frame.setJMenuBar(menu);
frame.getContentPane().add(label);
frame.getContentPane().add(panel);

frame.pack();
frame.setVisible(true);
}


I have added two different component in the same container, but only the last added component is displayed in the frame. why?
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing your code to specify a location:

 
krishna prasad gunasekaran
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works fine when i replaced mine with yours.so it is that we have to specify locations incase of multiple components. what if we are running out of locations.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> what if we are running out of locations.

never going to happen.

 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic