Horizontal Alignment Off for Dynamic Composite within a ScrolledComposite

51 Views Asked by At

I have a parent ScrolledComposite with a dynamic child Composite. When I delete a row, the alignment appears off when using the ScrolledComposite. I have tried this using just Composite instead of ScrolledComposite and it appears to work, so I am wondering if the scrolled layout is just not updating correctly.

Attached are some images showing 1 entry versus 3 entries. The area of interest is the Movable Rings section. The alignment is clearly off when a single entry, but near normal with 3 entries. Code below...

   /**
     * Create display area for movable rings.
     * 
     * @param topComposite
     */
    private void createMovableRingsComposite(Composite topComposite) {
        new Label(topComposite, SWT.NONE).setText("Movable Rings");
        Composite borderComposite = new Composite(topComposite, SWT.BORDER);
        borderComposite.setLayout(new GridLayout(1, false));
        borderComposite.setLayoutData(new GridData(
                GridData.HORIZONTAL_ALIGN_FILL));
        
        scroll = new ScrolledComposite(borderComposite,SWT.V_SCROLL|SWT.BORDER);
        GridLayout gridL = new GridLayout(1, false);
        GridData gridD = new GridData(SWT.FILL,SWT.FILL,true,true);
        gridD.heightHint = 200;
        scroll.setLayout(gridL);
        scroll.setLayoutData(gridD);
        scroll.setAlwaysShowScrollBars(true);
        scroll.setExpandHorizontal(true);
        scroll.setExpandVertical(true);

        movableRingsComposite = new Composite(scroll, SWT.NONE);
        movableRingsComposite.setLayoutData(new GridData(SWT.CENTER,
                SWT.CENTER, true, true, 1, 1));

        movableRingsComposite.setLayout(new GridLayout(6, false));
        // Make all the labels
        new Label(movableRingsComposite, SWT.NONE).setText("Show");
        new Label(movableRingsComposite, SWT.NONE).setText("ID");
        new Label(movableRingsComposite, SWT.NONE).setText("Lat");
        new Label(movableRingsComposite, SWT.NONE).setText("Lon");
        new Label(movableRingsComposite, SWT.NONE).setText("Radius");
        new Label(movableRingsComposite, SWT.NONE).setText("Labels");
        scroll.setContent(movableRingsComposite);

        
        Composite createComposite = new Composite(borderComposite, SWT.NONE);
        createComposite.setLayout(new GridLayout(3, false));
        createComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER,
                true, true, 1, 1));
        new Label(createComposite, SWT.NONE).setText("New at: ");

        pointsMenuButton = new MenuButton(createComposite);
        populatePointsMenuButton();

        pointsDataManager.addPointsChangedListener(this);

        pointsMenuButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                MenuButton menuButton = (MenuButton) e.widget;
                MenuItem mi = menuButton.getSelectedItem();
                addMovableRing(mi.getText());
                menuButton.setSelectedItem("Select One");
            }
        });

        Button delete = new Button(createComposite, SWT.PUSH);
        delete.setText("Delete");
        delete.addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                deleteMovableRing();
            }
        });
    }

    /**
     * Remove the ring of the selected movable ring row.
     */
    private void deleteMovableRing() {
        for (MovableRingRow row : movableRings) {
            if (row.isSelected()) {
                row.dispose();
                movableRings.remove(row);
                movableRingsComposite.layout(true); 
                getShell().pack();
                if (!movableRings.isEmpty()) {
                    movableRings.iterator().next().selectRow(true);
                }
                break;
            }
        }
    }

enter image description here enter image description here

0

There are 0 best solutions below