Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Problem removing row with TableEditor
Problem removing row with TableEditor [message #451741] Mon, 07 March 2005 23:21 Go to next message
bdiegel is currently offline bdiegelFriend
Messages: 1
Registered: July 2009
Junior Member
I have a table which uses a checkbox as the cell editor in the second
column. When I delete a row from the table, the table item is removed, but
the table editor in the second column is not. I've tried disposing of the
TableEditor as well as its Control, the checkbox. I've also tried calling
various layout, redraw and update methods on the table itself. Here's a
simple example:

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout(new FillLayout());

final Table table = new Table (shell, SWT.BORDER |
SWT.FULL_SELECTION );
for (int i=0; i<2; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setWidth (100);
}

final Vector editors = new Vector();

for (int i=0; i<20; i++) {
TableItem item = new TableItem (table, SWT.NONE);
item.setText (new String[] {"Item " + i, ""} );

TableEditor editor = new TableEditor(table);
Button button = new Button(table, SWT.CHECK);
button.pack ();

editor.minimumWidth = button.getSize().x;
editor.grabHorizontal = false;
editor.horizontalAlignment = SWT.CENTER;

editor.setEditor (null, item, 0);
editor.setEditor (button, item, 1);
editors.add(editor);
}
Button b = new Button(shell, SWT.PUSH);
b.setText("remove");
b.addSelectionListener( new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if ( table.getItemCount() > 0)
{
int row = table.getSelectionIndex();
table.remove(row);

//((TableEditor)editors.get(row)).getItem().dispose();
//((TableEditor)editors.get(row)).getEditor().dispose();
//((TableEditor)editors.get(row)).dispose();

//table.layout(true);
//table.redraw();
//table.update();
}
}
});

shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
Re: Problem removing row with TableEditor [message #451742 is a reply to message #451741] Tue, 08 March 2005 00:43 Go to previous message
Eclipse UserFriend
Originally posted by: zyang.bsu.edu

This is from a previous post. It may help you.

...
When you call Table.removeAll(), it disposes all the TableItems but it
does not dispose any of the StyledText widgets created for the
TableEditors. The StyledText widgets are created as children of the Table
and will only get disposed "for free" when you dispose the Table (or a
parent of the Table e.g. on shell closing). Therefore, when you do
removeAll() you should also dispose of all the StyledText and TableEditor
objects.
...


bdiegel wrote:

> I have a table which uses a checkbox as the cell editor in the second
> column. When I delete a row from the table, the table item is removed, but
> the table editor in the second column is not. I've tried disposing of the
> TableEditor as well as its Control, the checkbox. I've also tried calling
> various layout, redraw and update methods on the table itself. Here's a
> simple example:

> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> shell.setLayout(new FillLayout());

> final Table table = new Table (shell, SWT.BORDER |
> SWT.FULL_SELECTION );
> for (int i=0; i<2; i++) {
> TableColumn column = new TableColumn(table, SWT.NONE);
> column.setWidth (100);
> }

> final Vector editors = new Vector();

> for (int i=0; i<20; i++) {
> TableItem item = new TableItem (table, SWT.NONE);
> item.setText (new String[] {"Item " + i, ""} );

> TableEditor editor = new TableEditor(table);
> Button button = new Button(table, SWT.CHECK);
> button.pack ();

> editor.minimumWidth = button.getSize().x;
> editor.grabHorizontal = false;
> editor.horizontalAlignment = SWT.CENTER;

> editor.setEditor (null, item, 0);
> editor.setEditor (button, item, 1);
> editors.add(editor);
> }
> Button b = new Button(shell, SWT.PUSH);
> b.setText("remove");
> b.addSelectionListener( new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> if ( table.getItemCount() > 0)
> {
> int row = table.getSelectionIndex();
> table.remove(row);

> //((TableEditor)editors.get(row)).getItem().dispose();
> //((TableEditor)editors.get(row)).getEditor().dispose();
> //((TableEditor)editors.get(row)).dispose();

> //table.layout(true);
> //table.redraw();
> //table.update();
> }
> }
> });

> shell.pack ();
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
Previous Topic:[Browser 3.1M5a] javascript does not function on Linux within StatusTextListener
Next Topic:bug in CCombo?
Goto Forum:
  


Current Time: Fri Apr 26 15:26:29 GMT 2024

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

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

Back to the top