Copying JPanel components to another JPanel
- From: marcussilfver@xxxxxxxxx
- Date: Tue, 14 Aug 2007 08:48:59 -0700
I want to copy the contents of a jPanel to another JPanel, then I want
to empty the original JPanel.
I unsuccessfully tried the following:
jPanel1 = new JPanel();
jPanel1.setBounds(371, 112, 364, 28);
jPanel1.add(new JLabel("a"));
jPanel1.add(new JLabel("b"));
jPanel1.add(new JLabel("c"));
JPanel jp = new JPanel();
int numComponents = jPanel1.getComponentCount();
System.out.println("Number of components in jPanel1 is " +
numComponents);
for (int i=0; i<numComponents; i++)
{
jp.add(jPanel1.getComponent(i));
}
jPanel1.removeAll();
But I get an error like this
java.lang.ArrayIndexOutOfBoundsException: No such child: 2
at java.awt.Container.getComponent(Unknown Source)...
NOTE:
If I replace the row inside the loop with the following row:
System.out.println(jPanel1.getComponent(i).toString());
then I dont get an exception in getComponent, I then get a correct
standard out to the console!
So how can I achieve copying JPanel components? Am I way off?
.
- Follow-Ups:
- Re: Copying JPanel components to another JPanel
- From: Ville Oikarinen
- Re: Copying JPanel components to another JPanel
- From: Thomas Fritsch
- Re: Copying JPanel components to another JPanel
- Prev by Date: Re: Focus Traversal -- CTRL + (SHIFT) + TAB
- Next by Date: Re: Copying JPanel components to another JPanel
- Previous by thread: Focus Traversal -- CTRL + (SHIFT) + TAB
- Next by thread: Re: Copying JPanel components to another JPanel
- Index(es):
Relevant Pages
|
|