[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: Table not displaying inside a Composite
|
Hi,
Try to set a layout on your shell.
Boby
"Ruben Carvalho" <carvalho_ruben@xxxxxxxxxxx> wrote in message
news:7d68fcea63ad5257ee225950590a7842$1@xxxxxxxxxxxxxxxxxx
> 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
>