Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » calling a tableitem setText
calling a tableitem setText [message #460419] Thu, 25 August 2005 16:52 Go to next message
Eclipse UserFriend
Originally posted by: ignorante.ignorante.com

I try to call a function which is in other class [window1] to add a new
item in a table, but always I get an 'Error: "Widget is disposed"', so I
dont how to add a new item in this way.

what's wrong? what can i do? How can i call a function to add a new item?

Thanks.


public class main {
public static void main(String[] args) {
window1 w1 = new window1();
w1.createSShell();
w1.populateTable();
}
}



public class window1 {
private Shell sShell = null;
private Table table = null;
Display display = new Display();
private TableItem item = null;


public void createSShell() {
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.makeColumnsEqualWidth = true;
sShell = new Shell(display);
sShell.setText("Shell");
sShell.setLayout(gridLayout);
sShell.setSize(new Point(300, 200));
GridData grid = new GridData();
grid.grabExcessHorizontalSpace = true;
grid.horizontalAlignment = GridData.FILL;
createTable();

sShell.open();

while (!sShell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}


public void createTable() {
table = new Table(sShell, SWT.NONE);

TableColumn col1 = new TableColumn(table,SWT.LEFT);
col1.setText("COL1");
col1.setWidth(80);
TableColumn col2 = new TableColumn(table,SWT.LEFT);
col2.setText("COL2");
col2.setWidth(80);

table.setHeaderVisible(true);
table.setLinesVisible(true);

GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
table.setLayoutData(gridData);
}


public void populateTable(){
item = new TableItem(table,0);
item.setText(new String[] {"c1","c2"});
}
}
Re: calling a tableitem setText [message #460445 is a reply to message #460419] Fri, 26 August 2005 15:58 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
The problem is that your populateTable() method never gets invoked until
after the Shell and its child Table have been disposed. Your
read-and-dispatch loop should move to after populateTable() has been
invoked, so your main method would become:

public static void main(String[] args) {
window1 w1 = new window1();
w1.createSShell();
w1.populateTable();
while (!sShell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

....and the read-and-dispatch loop would be removed from
window1.createSShell().

Grant

"ignorante" <ignorante@ignorante.com> wrote in message
news:2bba01d9cfa2af07d0ba97c4ab0a517c$1@www.eclipse.org...
> I try to call a function which is in other class [window1] to add a new
> item in a table, but always I get an 'Error: "Widget is disposed"', so I
> dont how to add a new item in this way.
>
> what's wrong? what can i do? How can i call a function to add a new item?
>
> Thanks.
>
>
> public class main {
> public static void main(String[] args) {
> window1 w1 = new window1();
> w1.createSShell();
> w1.populateTable();
> }
> }
>
>
>
> public class window1 {
> private Shell sShell = null;
> private Table table = null;
> Display display = new Display();
> private TableItem item = null;
>
>
> public void createSShell() {
> GridLayout gridLayout = new GridLayout();
> gridLayout.numColumns = 3;
> gridLayout.makeColumnsEqualWidth = true;
> sShell = new Shell(display);
> sShell.setText("Shell");
> sShell.setLayout(gridLayout);
> sShell.setSize(new Point(300, 200));
> GridData grid = new GridData();
> grid.grabExcessHorizontalSpace = true;
> grid.horizontalAlignment = GridData.FILL;
> createTable();
>
> sShell.open();
>
> while (!sShell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>
>
> public void createTable() {
> table = new Table(sShell, SWT.NONE);
>
> TableColumn col1 = new TableColumn(table,SWT.LEFT);
> col1.setText("COL1");
> col1.setWidth(80);
> TableColumn col2 = new TableColumn(table,SWT.LEFT);
> col2.setText("COL2");
> col2.setWidth(80);
>
> table.setHeaderVisible(true);
> table.setLinesVisible(true);
>
> GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
> gridData.horizontalSpan = 3;
> table.setLayoutData(gridData);
> }
>
>
> public void populateTable(){
> item = new TableItem(table,0);
> item.setText(new String[] {"c1","c2"});
> }
> }
>
Re: calling a tableitem setText [message #460450 is a reply to message #460445] Fri, 26 August 2005 20:52 Go to previous message
Eclipse UserFriend
Originally posted by: ignorante.ignorante.com

Thank you!

Now I can understand that little problem about "dispose".

public class main {
public static void main(String[] args) {

window1 w1 = new window1();

w1.createSShell();
w1.populateTable();
while (!w1.sShell.isDisposed()) {
if (!w1.display.readAndDispatch()) w1.display.sleep();
}
w1.display.dispose();

}

}
Previous Topic:Running Eclipse with my own SWT jar
Next Topic:Proper display of Excel OLE object in view
Goto Forum:
  


Current Time: Thu Apr 22 15:19:55 GMT 2021

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

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

Back to the top