Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table not displaying inside a Composite
Table not displaying inside a Composite [message #454229] Tue, 19 April 2005 14:09 Go to next message
Eclipse UserFriend
Originally posted by: carvalho_ruben.yahoo.co.uk

Hello everybody,

I have just started working with Tables. I've started
with the snippets available at eclipse.org and
everything was ok.

In my application I want to put a Table inside a
Composite and it just doesn't work. I'm using Windows
XP and eclipse 3.0.2. Here is the code that I've
changed from Snippet103:

Thank you

import org.eclipse.swt.*;

public class TableTest {
static char content = 'a';

public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10, 10, 200, 240);

/* This is what I've added */
Composite c = new Composite(shell, SWT.NONE);

FillLayout f = new FillLayout();
c.setLayout(f);

/* Now I create the table with a composite instead
of using a Shell */
Table table = new Table(c, SWT.BORDER);
table.setBounds(10, 10, 160, 160);

final TableItem[] items = new TableItem[4];
for (int i = 0; i < 4; i++) {
new TableColumn(table, SWT.NONE).setWidth(40);
}
for (int i = 0; i < 4; i++) {
items[i] = new TableItem(table, SWT.NONE);
populateItem(items[i]);
}

Button button = new Button(shell, SWT.PUSH);
button.setBounds(10, 180, 50, 30);
button.setText("Change");
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
for (int i = 0; i < 4; i++) {
populateItem(items[i]);
}
}
});

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

static void populateItem(TableItem item) {
String stringContent = String.valueOf(content);
item.setText(new String[] { stringContent,
stringContent, stringContent, stringContent });
content++;
if (content > 'z')
content = 'a';
}
}

Rúben Carvalho
Re: Table not displaying inside a Composite [message #454235 is a reply to message #454229] Tue, 19 April 2005 15:19 Go to previous messageGo to next message
Robert Bacs is currently offline Robert BacsFriend
Messages: 165
Registered: July 2009
Senior Member
Hi,

Try to set a layout on your shell.

Boby

"Ruben Carvalho" <carvalho_ruben@yahoo.co.uk> wrote in message
news:7d68fcea63ad5257ee225950590a7842$1@www.eclipse.org...
> Hello everybody,
>
> I have just started working with Tables. I've started
> with the snippets available at eclipse.org and
> everything was ok.
>
> In my application I want to put a Table inside a
> Composite and it just doesn't work. I'm using Windows
> XP and eclipse 3.0.2. Here is the code that I've
> changed from Snippet103:
>
> Thank you
>
> import org.eclipse.swt.*;
>
> public class TableTest {
> static char content = 'a';
>
> public static void main(String[] args) {
> final Display display = new Display();
> Shell shell = new Shell(display);
> shell.setBounds(10, 10, 200, 240);
>
> /* This is what I've added */
> Composite c = new Composite(shell, SWT.NONE);
>
> FillLayout f = new FillLayout();
> c.setLayout(f);
>
> /* Now I create the table with a composite instead
> of using a Shell */
> Table table = new Table(c, SWT.BORDER);
> table.setBounds(10, 10, 160, 160);
>
> final TableItem[] items = new TableItem[4];
> for (int i = 0; i < 4; i++) {
> new TableColumn(table, SWT.NONE).setWidth(40);
> }
> for (int i = 0; i < 4; i++) {
> items[i] = new TableItem(table, SWT.NONE);
> populateItem(items[i]);
> }
>
> Button button = new Button(shell, SWT.PUSH);
> button.setBounds(10, 180, 50, 30);
> button.setText("Change");
> button.addListener(SWT.Selection, new Listener() {
> public void handleEvent(Event event) {
> for (int i = 0; i < 4; i++) {
> populateItem(items[i]);
> }
> }
> });
>
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
>
> static void populateItem(TableItem item) {
> String stringContent = String.valueOf(content);
> item.setText(new String[] { stringContent,
> stringContent, stringContent, stringContent });
> content++;
> if (content > 'z')
> content = 'a';
> }
> }
>
> R
Re: Table not displaying inside a Composite [message #454317 is a reply to message #454235] Wed, 20 April 2005 10:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: carvalho_ruben.yahoo.co.uk

Thanks a million.

That was it. Somehow, if the Shell doesn't have a layout and if you put a
Table inside a composite in a Shell, the Table does not show, even if the
Composite has a Layout.

Rúben Carvalho
Re: Table not displaying inside a Composite [message #454330 is a reply to message #454317] Wed, 20 April 2005 15:57 Go to previous message
Robert Bacs is currently offline Robert BacsFriend
Messages: 165
Registered: July 2009
Senior Member
Well, the Shell is a composite too and if you want to display something on
it you need to set a layout or set the bounds for the child widgets.

Regards,
Boby

"Ruben Carvalho" <carvalho_ruben@yahoo.co.uk> wrote in message
news:de6a7d9036a4a02792139a377ccfb352$1@www.eclipse.org...
>
> Thanks a million.
>
> That was it. Somehow, if the Shell doesn't have a layout and if you put a
> Table inside a composite in a Shell, the Table does not show, even if the
> Composite has a Layout.
>
> R
Previous Topic:Changing default non-focus selection in list and quick-fixes
Next Topic:SWT Browser mousehandling
Goto Forum:
  


Current Time: Tue Apr 16 07:30:40 GMT 2024

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

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

Back to the top