views:

499

answers:

0

I am new to SWT but have plenty of experience w/ other GUI layout managers. I have run in two a weird problem when nesting a composite inside of another composite.

http://www.swooby.com/swt/nestedcontrolproblem.png

If I run the audiocontrol as a standalone bean it works fine. If I run it nested in another composite it starts to act funny. When I add this composite to a more complex parent (6 columns), the nested composite does not seem to be honoring its own class defined horizontal span correctly.

The audiocontrol lays out fine in a lesser complex parent (total of 2 columns).

I am using Eclipse Visual Editor to lay these out, so I have not written any of my own code to alter the layout (except to change a Composite type to CompositeAudio).

Code to repro this: Parent.java

package com.twistpair.qa;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;

public class Parent extends Composite {

    private AudioControl compositeAudio = null;

    public Parent(Composite parent, int style) {
        super(parent, style);
        initialize();
    }

    private void initialize() {
        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 2;
        this.setLayout(gridLayout);
        createCompositeAudio();
        setSize(new Point(97, 673));
    }

    /**
     * This method initializes compositeAudio   
     *
     */
    private void createCompositeAudio() {
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.CENTER;
        gridData.grabExcessHorizontalSpace = false;
        gridData.grabExcessVerticalSpace = false;
        gridData.horizontalSpan = 2;
        gridData.verticalAlignment = GridData.CENTER;
        compositeAudio = new AudioControl(this, SWT.NONE);
        compositeAudio.setLayout(new GridLayout());
        compositeAudio.setLayoutData(gridData);
    }

}  //  @jve:decl-index=0:visual-constraint="36,7"

AudioControl.java:

package com.twistpair.qa;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;

public class AudioControl extends Composite {

    private CLabel cLabelAudio = null;
    private Button checkBoxRunning = null;
    private CLabel cLabelVolume = null;
    private Scale scaleVolumeLeft = null;
    private CLabel cLabelVuMeter = null;
    private Canvas canvasVuMeterLeft = null;
    private Button checkBoxMuteRx = null;
    private Button checkBoxMuteTx = null;
    private Button checkBoxMuteBoth = null;
    private Scale scaleVolumeRight = null;
    private Canvas canvasVuMeterRight = null;

    public AudioControl(Composite parent, int style) {
        super(parent, style);
        initialize();
    }

    private void initialize() {
        GridData gridData31 = new GridData();
        gridData31.horizontalAlignment = GridData.CENTER;
        gridData31.verticalAlignment = GridData.CENTER;
        GridData gridData21 = new GridData();
        gridData21.horizontalAlignment = GridData.CENTER;
        gridData21.verticalAlignment = GridData.CENTER;
        GridData gridData11 = new GridData();
        gridData11.horizontalSpan = 2;
        GridData gridData5 = new GridData();
        gridData5.horizontalSpan = 2;
        gridData5.verticalAlignment = GridData.CENTER;
        gridData5.horizontalAlignment = GridData.CENTER;
        GridData gridData4 = new GridData();
        gridData4.horizontalSpan = 2;
        gridData4.verticalAlignment = GridData.CENTER;
        gridData4.horizontalAlignment = GridData.CENTER;
        GridData gridData3 = new GridData();
        gridData3.horizontalSpan = 2;
        gridData3.verticalAlignment = GridData.CENTER;
        gridData3.horizontalAlignment = GridData.CENTER;
        GridData gridData2 = new GridData();
        gridData2.horizontalSpan = 2;
        GridData gridData1 = new GridData();
        gridData1.horizontalSpan = 2;
        GridData gridData = new GridData();
        gridData.horizontalSpan = 2;
        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 2;
        cLabelAudio = new CLabel(this, SWT.NONE);
        cLabelAudio.setText("Audio");
        cLabelAudio.setFont(new Font(Display.getDefault(), "Segoe UI", 9, SWT.BOLD));
        cLabelAudio.setLayoutData(gridData5);
        checkBoxRunning = new Button(this, SWT.CHECK);
        checkBoxRunning.setText("Running");
        checkBoxRunning.setLayoutData(gridData11);
        cLabelVolume = new CLabel(this, SWT.NONE);
        cLabelVolume.setText("Volume");
        cLabelVolume.setFont(new Font(Display.getDefault(), "Segoe UI", 9, SWT.BOLD));
        cLabelVolume.setLayoutData(gridData4);
        scaleVolumeLeft = new Scale(this, SWT.VERTICAL);
        scaleVolumeLeft.setLayoutData(gridData21);
        scaleVolumeRight = new Scale(this, SWT.VERTICAL);
        scaleVolumeRight.setLayoutData(gridData31);
        cLabelVuMeter = new CLabel(this, SWT.NONE);
        cLabelVuMeter.setText("VU Meter");
        cLabelVuMeter.setFont(new Font(Display.getDefault(), "Segoe UI", 9, SWT.BOLD));
        cLabelVuMeter.setLayoutData(gridData3);
        createCanvasVuMeterLeft();
        this.setLayout(gridLayout);
        this.setSize(new Point(151, 415));
        createCanvasVuMeterRight();
        checkBoxMuteRx = new Button(this, SWT.CHECK);
        checkBoxMuteRx.setText("Mute RX");
        checkBoxMuteRx.setLayoutData(gridData);
        checkBoxMuteTx = new Button(this, SWT.CHECK);
        checkBoxMuteTx.setText("Mute TX");
        checkBoxMuteTx.setLayoutData(gridData1);
        checkBoxMuteBoth = new Button(this, SWT.CHECK);
        checkBoxMuteBoth.setText("Mute Both");
        checkBoxMuteBoth.setLayoutData(gridData2);
    }

    /**
     * This method initializes canvasVuMeterLeft    
     *
     */
    private void createCanvasVuMeterLeft() {
        canvasVuMeterLeft = new Canvas(this, SWT.BORDER);
    }

    /**
     * This method initializes canvasVuMeterRight   
     *
     */
    private void createCanvasVuMeterRight() {
        canvasVuMeterRight = new Canvas(this, SWT.BORDER);
    }

}  //  @jve:decl-index=0:visual-constraint="10,10"

My other problem was that the audiocontrol initially had the three "Mute *" checkboxes underneath the two VU (left/right) canvases. In a lesser complex parent the layout was mostly behaving, but the three checkboxes below the VU canvases were not being created. I used a spy program to browse the running UI, and the controls were indeed not there. The code did have valid objects that I could manipulate. I thought this was weird, and seem to have temporarily solved the problem by just moving the checkboxes, but I think this could be an indicator that there is something wrong w/ my audiocontrol.

Has anyone seen anything like these two problems? I searched the net and stackoverflow and didn't see anything directly related.

Thanks!

Pv