Remove all Childs from IFigure doesn't work ... !? [message #131470] |
Mon, 10 May 2004 09:49 |
Eclipse User |
|
|
|
Originally posted by: Kay_1.gmx.de
Hello!
I have a problem with the following method. I want to remove all childs =
from
an IFigure, which i used as 'panel' for them:
IFigure panel;
:
:
void clearPanel()
{
try
{
allChilds =3D panel.getChildren();
int len =3D allChilds.size();
=
for (int i =3D 0; i < len; i++)
{
panel.remove((IFigure)allChilds.get(i));
}
=
}catch(Exception ex){System.out.println("clearPanel: "+ex); }
=
}
I get an IndexOutOfBounds Exception, but i dont know why. The =
IFigureChilds are
added to an IFigrue labeled 'panel'.
Thx,
eyak
-- =
Erstellt mit M2, Operas revolution=E4rem E-Mail-Modul: =
http://www.opera.com/m2/
|
|
|
Re: Remove all Childs from IFigure doesn't work ... !? [message #131497 is a reply to message #131470] |
Mon, 10 May 2004 14:46 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
Your caching the length of the list, but then you're removing from it as you
run over that length - as soon as you remove one item you have an invalid
length. Why don't you try an iterator and call iterator.remove()?
"eyak" <Kay_1@gmx.de> wrote in message news:opr7r2wfv9egwbjz@localhost...
Hello!
I have a problem with the following method. I want to remove all childs
from
an IFigure, which i used as 'panel' for them:
IFigure panel;
:
:
void clearPanel()
{
try
{
allChilds = panel.getChildren();
int len = allChilds.size();
for (int i = 0; i < len; i++)
{
panel.remove((IFigure)allChilds.get(i));
}
}catch(Exception ex){System.out.println("clearPanel: "+ex); }
}
I get an IndexOutOfBounds Exception, but i dont know why. The
IFigureChilds are
added to an IFigrue labeled 'panel'.
Thx,
eyak
--
Erstellt mit M2, Operas revolution
|
|
|
Re: Remove all Childs from IFigure doesn't work ... !? [message #131524 is a reply to message #131497] |
Mon, 10 May 2004 15:25 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
Manipulating the array directly would bypass some other stuff which should
happen. For example, calling removeNotify() on the child figures.
The best way to do this is just to loop backwards instead of forwards. This
also avoids calling System.arrayCopy() N times.
"Whitney Sorenson" <none@us.ibm.com> wrote in message
news:c7o0ma$huf$1@eclipse.org...
> Your caching the length of the list, but then you're removing from it as
you
> run over that length - as soon as you remove one item you have an invalid
> length. Why don't you try an iterator and call iterator.remove()?
>
> "eyak" <Kay_1@gmx.de> wrote in message news:opr7r2wfv9egwbjz@localhost...
> Hello!
>
> I have a problem with the following method. I want to remove all childs
> from
> an IFigure, which i used as 'panel' for them:
>
> IFigure panel;
>
> :
> :
>
> void clearPanel()
> {
> try
> {
> allChilds = panel.getChildren();
> int len = allChilds.size();
>
> for (int i = 0; i < len; i++)
> {
> panel.remove((IFigure)allChilds.get(i));
> }
>
> }catch(Exception ex){System.out.println("clearPanel: "+ex); }
>
> }
>
>
> I get an IndexOutOfBounds Exception, but i dont know why. The
> IFigureChilds are
> added to an IFigrue labeled 'panel'.
>
>
> Thx,
> eyak
>
>
>
>
>
> --
> Erstellt mit M2, Operas revolution
|
|
|
Powered by
FUDForum. Page generated in 0.02545 seconds