Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » RefreshProblem: Adding new TableItem with TableEditor (New EditorControls only appear if Scrollbar is hit)
RefreshProblem: Adding new TableItem with TableEditor [message #645167] Wed, 15 December 2010 18:45 Go to next message
gerald r. is currently offline gerald r.Friend
Messages: 5
Registered: December 2010
Junior Member

i am currently working on a table which allows to add new raws.
I am using TableEditor to create Buttons in each raw.

It almost works, but the new controls don't appear.
Instead they apear after hitting the scrollbar or forcing a redraw in some other way.

layout(true) does not help.

Here an example:

package test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class SWTTest {
	private static Shell shell;

	public static void main(String[] args) {
	    Display display = new Display();
	    shell = new Shell(display);
	    //creating table
	    Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
	    table.setSize(200, 200);
	    //creating columns
	    //creating initial items
	    for (int i = 0; i < 12; i++) {
	      TableItem item = new TableItem(table, SWT.NONE);
	      item.setText(new String[]{"Item " + i,"_____"});
	    //adding the TableEditors

	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch())

	private static void addColumns(Table table) {
		TableColumn tc = new TableColumn(table,SWT.NULL);
		tc = new TableColumn(table,SWT.NULL);
		tc.setText("And so");

	private static void addEditors(final Table table) {
		for(TableItem item:table.getItems()){
			createEditor(table, item, false);

	protected static void createEditor(final Table table,TableItem item,boolean isNew){
		TableEditor editor = new TableEditor(table);
		Button button = new Button(table,SWT.PUSH);
		button.addSelectionListener(new SelectionListener(){

			public void widgetDefaultSelected(SelectionEvent e) {

			public void widgetSelected(SelectionEvent e) {
				//if button gets pushed, create a new item 
				Button button = (Button)e.widget;
				TableItem item = (TableItem)button.getData("item");
				int index = table.indexOf(item);
					//add the new item
					//try to force layout, doesnt help :(

				}catch(Throwable t){
		//force the layout directly with the editor, doesnt help either

	protected static void addItem(final Table table, int index,String formerLabel) {
		TableItem item = new TableItem(table, SWT.NONE, index+1);
		item.setText(new String[]{formerLabel + "new","_____"});

		createEditor(table, item, true);


In the example the first "adding" works. But it only does beacause a scrollbar is created and so the table needs to redraw.

After that every new Control only apears if i force a redraw.

Its tested with Windows XP and the Eclipse version 3.3 and 3.5.

I hope someone can help me, because i really thing this must be a trivial thing. But i cant make it work Sad

all the best,
Re: RefreshProblem: Adding new TableItem with TableEditor [message #645373 is a reply to message #645167] Thu, 16 December 2010 19:04 Go to previous messageGo to next message
Lakshmi P ShanmugamFriend
Messages: 277
Registered: July 2009
Location: India
Senior Member

When a new item is added all the editors have to be laid out again. And calling editor.layout or table.layout doesn't do this.
Please see this thread for a discussion on this behavior. --> 6&S=f1cb13e717d98051e4be42274f216e0d#msg_634126
Though the topic there is removing an item, the reason and workaround are the same for adding an item.


Lakshmi P Shanmugam
Re: RefreshProblem: Adding new TableItem with TableEditor [message #645736 is a reply to message #645373] Mon, 20 December 2010 10:20 Go to previous message
gerald r. is currently offline gerald r.Friend
Messages: 5
Registered: December 2010
Junior Member
wow, thanks.

by using "table.notifyListeners(SWT.Resize, new Event());" it works now. Smile

Previous Topic:GridLayout using Groups members
Next Topic:[Browser] How to know when setURL has finished
Goto Forum:

Current Time: Thu Mar 04 17:03:17 GMT 2021

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

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

Back to the top