Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2228

Copying JPanel components

From "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this>
Subject Copying JPanel components
Message-ID <1187106539.387400.115730@19g2000hsx.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:37 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
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?

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Copying JPanel components "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
  Re: Copying JPanel compon "Thomas Fritsch" <thomas.fritsch@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
    Re: Copying JPanel compon "bcr666" <bcr666@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
  Re: Copying JPanel compon "Ville Oikarinen" <ville.oikarinen@THRWHITE.remove-dii-this> - 2011-04-27 15:37 +0000
    Re: Copying JPanel compon "Larry Barowski" <larry.barowski@THRWHITE.remove-dii-this> - 2011-04-27 15:38 +0000

csiph-web