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 |
Eclipse User |
|
|
|
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 |
Robert Bacs 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 |
Eclipse User |
|
|
|
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
|
|
| |
Goto Forum:
Current Time: Sat Apr 27 02:01:16 GMT 2024
Powered by FUDForum. Page generated in 0.02888 seconds
|