我是SWT GUI开发的新手。我正在使用SWT开发Eclipse插件。基本上,我想要第二个无线电选项组下面的两个无线电选项组和一些文本框;如下所示。
Heading1
. A radio button
. B radio button
Heading2
. C radio button
. D radio button
Textbox1 Textbox2 Textbox3
由于我需要相对于彼此的文本框,我使用了FormLayout 。但它给了我例外:
引起:java.lang.ClassCastException:org.eclipse.swt.layout.FormData无法强制转换为org.eclipse.swt.layout.GridData *
但我没有使用GridData
。
例外情况发生在第129行。
我无法相对于Textbox1添加Textbox2。我的代码如下。
Shell sh = new Shell(parent_shell,SWT.PRIMARY_MODAL | SWT.TRAIL | SWT.CASCADE);
System.out.println("execute");
FormLayout fL = new FormLayout();
sh.setLayout(fL);
sh.setText("Configure");
sh.setSize(330,300);
sh.setActive();
Composite composite = new Composite( sh, SWT.NONE );
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout( layout );
FormData fd = new FormData(); //line 100
fd.top = new FormAttachment(0,0);//line 101
fd.left = new FormAttachment(0,0);//line 102
//fd.right = new FormAttachment(26);//line 103
//fd.bottom = new FormAttachment(10);//line 104
composite.setLayoutData( fd );
RadioGroupFieldEditor rgfe = new RadioGroupFieldEditor("User Choice",
"Heading1", 1, new String[][]{
{"A radio button","a"},{"B radio button","b"}
}, composite,false);
RadioGroupFieldEditor rgfe1 = new RadioGroupFieldEditor("User Choice1",
"Heading2", 1, new String[][]{
{"C radio button","c"},{"D radio button","d"}
}, composite,false);
Text ol = new Text(composite,SWT.READ_ONLY);
ol.setText("Output Location");
ol.setEnabled(false);
// FormData fd1 = new FormData();
// fd.top = new FormAttachment(fd);
// fd.left = new FormAttachment(1);
// fd.right = new FormAttachment(26);
// fd.bottom = new FormAttachment(10);
// ol.pack();
// ol.setLayoutData(fd1); //line 129 --> exception occurs
while (!sh.isDisposed()) {
if (!parent_display.readAndDispatch()) {
parent_display.sleep();
}
}
}
答案 0 :(得分:0)
RadioGroupFieldEditor
假设其父级设置为GridLayout
。
我建议您将RadioGroupFieldEditor
嵌入到具有Composite
集的单独GridLayout
中。然后,您可以将FormData附加到Composite以控制其布局。
例如:
Composite composite = new Composite( sh, SWT.NONE );
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout( layout );
FormData compositeFormData = new FormData();
...
composite.setLayoutData( compositeFormData );
RadioGroupFieldEditor fieldEditor = new RadioGroupFieldEditor( ..., composite, ... );