Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT nested composite layout problem
SWT nested composite layout problem [message #508674] |
Tue, 19 January 2010 19:27 |
Paul Peavyhouse Messages: 4 Registered: January 2010 |
Junior Member |
|
|
I am new to SWT but have plenty of experience w/ other GUI layout managers (C#, wxPython, etc).
I have run in to a weird problem when nesting a composite inside of another composite.
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.
Basically, the nested composite does not seem to be honoring its own privately class defined horizontal span correctly.
In the past I had been able to get the nested control to lay out fine in a lesser complex parent (total of 2 columns), but I can't seem to do that any more either.
I am using Eclipse Visual Editor (1.4.0.v20090826-1446-777N-CcNBC0BwNk5HZZk) in a fresh Eclipse 3.5 install w/ all of the latest updates.
I have made only one change to the VE auto-generated code; change the nested Composite type to AudioControl.
The code to repro this follows...
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"
I will volunteer that I had another weird possibly related problem. The audiocontrol initially had the three "Mute *" checkboxes underneath the two VU (left/right) Canvas subclasses. As a stand-alone bean the layout was looked fine, but when run as a application 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...but the code did have valid objects that I could manipulate.
I thought this was weird, and I seemed 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/ either my audiocontrol or my VE plugin install.
Has anyone seen anything like these two problems? I searched the net didn't see anything directly related.
Thanks!
Pv
|
|
|
Re: SWT nested composite layout problem [message #509892 is a reply to message #508674] |
Mon, 25 January 2010 16:47 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi,
I added a main() to your snippet, stuck the two classes together into one
file, and it seems like it works for me, unless I'm looking for the wrong
thing. I've pasted it below, can you see if it works for you or shows the
problem? If it works, are you able to change it to show the problem? Or
alternatively, if you see a difference here that acn be applied to your case
to make it start working then we'll be done.
public class Parent extends Composite {
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);
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);
}
private void createCanvasVuMeterLeft() {
canvasVuMeterLeft = new Canvas(this, SWT.BORDER);
}
private void createCanvasVuMeterRight() {
canvasVuMeterRight = new Canvas(this, SWT.BORDER);
}
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
// shell.setBounds(10,10,200,200);
shell.setLayout(new FillLayout());
new Parent(shell, SWT.BORDER);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
/* start Parent class */
private AudioControl compositeAudio = null;
public Parent(Composite parent, int style) {
super(parent, style);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
this.setLayout(gridLayout);
createCompositeAudio();
new Button(this, SWT.PUSH).setText("hi1");
new Button(this, SWT.PUSH).setText("hi2");
new Button(this, SWT.PUSH).setText("hi3");
// setSize(new Point(97, 673)); // not needed since layout being
used
}
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.BORDER);
compositeAudio.setLayout(new GridLayout());
compositeAudio.setLayoutData(gridData);
}
}
}
Grant
"Paul Peavyhouse" <pv@swooby.com> wrote in message
news:hj512f$abj$1@build.eclipse.org...
> I am new to SWT but have plenty of experience w/ other GUI layout managers
(C#, wxPython, etc).
> I have run in to a weird problem when nesting a composite inside of
another composite.
>
>
>
> 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.
> Basically, the nested composite does not seem to be honoring its own
privately class defined horizontal span correctly.
>
> In the past I had been able to get the nested control to lay out fine in a
lesser complex parent (total of 2 columns), but I can't seem to do that any
more either.
>
> I am using Eclipse Visual Editor
(1.4.0.v20090826-1446-777N-CcNBC0BwNk5HZZk) in a fresh Eclipse 3.5 install
w/ all of the latest updates.
> I have made only one change to the VE auto-generated code; change the
nested Composite type to AudioControl.
>
> The code to repro this follows...
> 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"
>
>
> I will volunteer that I had another weird possibly related problem. The
audiocontrol initially had the three "Mute *" checkboxes underneath the two
VU (left/right) Canvas subclasses. As a stand-alone bean the layout was
looked fine, but when run as a application 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...but the code did have valid objects that I could
manipulate.
> I thought this was weird, and I seemed 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/ either my audiocontrol or my VE
plugin install.
>
> Has anyone seen anything like these two problems? I searched the net
didn't see anything directly related.
>
> Thanks!
>
> Pv
|
|
| | | |
Re: SWT nested composite layout problem [message #510482 is a reply to message #510243] |
Wed, 27 January 2010 15:37 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Sorry, I thought the problem behaviour was different, my newsreader didn't
include the screenshots from your initial post. Now that I see them, I see
that the GridLayout on your compositeAudio needs to specify that it has two
columns, something like compositeAudio.setLayout(new GridLayout(2, true)).
Everything else looks fine.
Grant
"Paul Peavyhouse" <pv@swooby.com> wrote in message
news:hjnl65$dut$1@build.eclipse.org...
> I tried on WinXP 32-bit w/ a fresh install of Eclipse 3.5.1 SR1, no
plugins, and the layout is still bad. :(
>
> All machines used are running JDK 6u17.
>
> I create a new project, drop your code in, and then add an External Jar
reference to:
> C:\Program Files\eclipse\plugins\org.eclipse.swt.win32.win32.x86_3.5.1.
v3555a.jar
> C:\Program Files\eclipse\plugins\org.eclipse.swt_3.5.1.v3555a.jar
>
> Pv
|
|
|
Goto Forum:
Current Time: Mon Dec 09 03:50:30 GMT 2024
Powered by FUDForum. Page generated in 0.06345 seconds
|