swt Table wächst über das Composite hinaus

Alvine

Grünschnabel
Hallo,
ich habe eine swt Table. Initial hat sie keine Elemente, jedoch einen "Add"-Button, der jeweils eine neue Zeile zur Tabelle hinzufügt. Bis hierher funktioniert es auch.
Wenn die Tabelle jedoch größer wird, als der ihm zur Verfügung stehende Platz, so "rutscht" mein "Add"-Button leider unten aus dem sichtabren Bereich. Am liebesten wäre mir, wenn die Tabelle nur bis zum Rand wächst und dann einen Scrollbalken erhält., sodass es weiterhin möglich ist neue Zeilen zu erzeugen.
Code:
// parent Composite
        final Composite parent = new Composite(compProperties, SWT.NONE);
        localPropertiesComp.setLayout(new FormLayout());
        final FormData formDataLocalPropertiesComp = new FormData();
        formDataLocalPropertiesComp.top = new FormAttachment(topComposite, 5);
        formDataLocalPropertiesComp.left = new FormAttachment(0, 5);
        formDataLocalPropertiesComp.right = new FormAttachment(100, -5);
        formDataLocalPropertiesComp.bottom = new FormAttachment(100, -10);
        localPropertiesComp.setLayoutData(formDataLocalPropertiesComp);

        final Group group= new Group(parent , SWT.NONE);
        group.setLayout(new FormLayout());
        group.setText("Group");
        final FormData formDataBorder2 = new FormData();
        formDataBorder2.right = new FormAttachment(100, -5);
        formDataBorder2.left = new FormAttachment(0, 5);
        formDataBorder2.top = new FormAttachment(0, 5);
        group.setLayoutData(formDataBorder2);

        // local properties table
        final Table localTable = new Table(group, SWT.BORDER);
        localTable.setLinesVisible(true);
        localTable.setHeaderVisible(true);
        FormData formDataTable2 = new FormData();
        formDataTable2.right = new FormAttachment(100, -5);
        formDataTable2.left = new FormAttachment(0, 5);
        formDataTable2.top = new FormAttachment(0, 5);
        localTable.setLayoutData(formDataTable2);

        // first column -key-
        TableColumn keyColumn2 = new TableColumn(localTable, SWT.NONE);
        keyColumn2.setWidth(200);
        keyColumn2.setText("Key");

        // second column -value-
        TableColumn valueColumn2 = new TableColumn(localTable, SWT.NONE);
        valueColumn2.setWidth(200);
        valueColumn2.setText("Value");

        // third column -Button delete-
        TableColumn buttonColumn2 = new TableColumn(localTable, SWT.NONE);
        buttonColumn2.setWidth(250);
        buttonColumn2.setText("Delete");

        Button addRowButton = new Button(localBorder, SWT.NONE);
        addRowButton.setText("+");
        addRowButton.setToolTipText("irgendwas");
        FormData formDataAddRowButton = new FormData();
        formDataAddRowButton.left = new FormAttachment(0, 5);
        formDataAddRowButton.top = new FormAttachment(localTable, 5);
        addRowButton.setLayoutData(formDataAddRowButton);
        addRowButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                new TableItem(localTable, SWT.NONE).setText("" + counter);
                group.pack();
                parent .layout();
                counter++;
            }
        });
 

Anhänge

  • Screen.JPG
    Screen.JPG
    47,3 KB · Aufrufe: 24
Zuletzt bearbeitet:
Zurück