Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Unable to dispose TableColumn
Unable to dispose TableColumn [message #454782] Thu, 28 April 2005 14:58 Go to next message
Neeraj is currently offline NeerajFriend
Messages: 18
Registered: July 2009
Junior Member
I am not able to delete all the columns in the table? The following code
will help you, i think.

System.out.println("before dispose" + table.getColumnCount());
for(int i = 0; i < table.getColumnCount(); i++)
{
table.getColumn(i).dispose();
}
System.out.println("after dispose " + table.getColumnCount());

The result i got was:
before dispose : 8
after dispose : 4

Initially there were 8 columns
Please suggest a way to delete all the columns.
Re: Unable to dispose TableColumn [message #454784 is a reply to message #454782] Thu, 28 April 2005 15:22 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Reverse the order of your loop:

System.out.println("before dispose" + table.getColumnCount());
for(int i = table.getColumnCount() -1; i <= 0; i++)
{
table.getColumn(i).dispose();
}
System.out.println("after dispose " + table.getColumnCount());


"Neeraj" <neerajkrishnag@yahoo.com> wrote in message
news:8002e17c8c0453ceb41f50e447957a62$1@www.eclipse.org...
>I am not able to delete all the columns in the table? The following code
>will help you, i think.
> System.out.println("before dispose" + table.getColumnCount());
> for(int i = 0; i < table.getColumnCount(); i++)
> {
> table.getColumn(i).dispose();
> }
> System.out.println("after dispose " + table.getColumnCount());
>
> The result i got was:
> before dispose : 8 after dispose : 4
>
> Initially there were 8 columns
> Please suggest a way to delete all the columns.
>
Re: Unable to dispose TableColumn [message #454798 is a reply to message #454784] Fri, 29 April 2005 02:19 Go to previous messageGo to next message
Neeraj is currently offline NeerajFriend
Messages: 18
Registered: July 2009
Junior Member
Thank you, that resolved my problem... But i just want to know how
reversing the order of the loop works??
Your code had some errors.... So i am rewriting it for others to get a
easy answer:
System.out.println("before dispose" + table.getColumnCount());
for(int i = table.getColumnCount() -1; i >= 0; i--)
{
//tc[i].dispose();
table.getColumn(i).dispose();
}
System.out.println("after dispose " + table.getColumnCount());

Of course thanks again for providing the soln...and thanks from all those
who faced the same problem.
Re: Unable to dispose TableColumn [message #454833 is a reply to message #454798] Fri, 29 April 2005 18:31 Go to previous message
Emil Crumhorn is currently offline Emil CrumhornFriend
Messages: 169
Registered: July 2009
Senior Member
You reverse the order because you have to delete items from the end to the
beginning or your index will be incorrect after you remove the first one.

Think it of it as a train with cars (that's leaning downhill), if you go
from left to right, and remove one in the middle, all the other ones will
stack up to fill up the space of the missing car, but as you keep counting
normally, your next index will now be off by one as there's 1 car missing.
Or: If you removed car 2, and then wanted to remove car 3, going from left
to right, you'd be at car 4 for index 3. Doing it from the back, you don't
have to worry about the cars that stack up as you're already done with those
and the part that your modifying doesn't change.

Maybe not the best analogy, but I hope you get the idea =)

Emil

"Neeraj" <neerajkrishnag@yahoo.com> wrote in message
news:4c64613169fe45fb8cf481c9c1dc30f8$1@www.eclipse.org...
> Thank you, that resolved my problem... But i just want to know how
> reversing the order of the loop works??
> Your code had some errors.... So i am rewriting it for others to get a
> easy answer:
> System.out.println("before dispose" + table.getColumnCount());
> for(int i = table.getColumnCount() -1; i >= 0; i--)
> {
> //tc[i].dispose();
> table.getColumn(i).dispose();
> }
> System.out.println("after dispose " + table.getColumnCount());
>
> Of course thanks again for providing the soln...and thanks from all those
> who faced the same problem.
>
Previous Topic:Professional SWT The Standard Widget Toolkit Volume 2, when?
Next Topic:Print the Browser widget
Goto Forum:
  


Current Time: Tue May 14 13:17:24 GMT 2024

Powered by FUDForum. Page generated in 0.04217 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top