gpt4 book ai didi

java - 将 RadioGroupFieldEditor 放置在 FormLayout 中时出现 ClassCastException

转载 作者:太空宇宙 更新时间:2023-11-04 11:47:36 24 4
gpt4 key购买 nike

我是 SWT GUI 开发的新手。我正在使用 SWT 开发 Eclipse 插件。基本上,我想要两个单选选项组和第二个单选选项组下方的一些文本框;像下面这样。

    Heading1
. A radio button
. B radio button
Heading2
. C radio button
. D radio button
Textbox1 Textbox2 Textbox3

由于我需要这些文本框相互关联,所以我使用了 FormLayout。但这给了我异常(exception):

Caused by: java.lang.ClassCastException: org.eclipse.swt.layout.FormData cannot be cast to 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();
}
}

}

最佳答案

RadioGroupFieldEditor 假定其父级设置了 GridLayout

我建议您将 RadioGroupFieldEditor 嵌入到具有 GridLayout 集的单独 Composite 中。然后您可以将 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, ... );

关于java - 将 RadioGroupFieldEditor 放置在 FormLayout 中时出现 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42187360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com