我正在尝试在单击按钮时添加文本框,按钮等小部件.我试过了,但我只能动态地添加这些小部件,最多只能达到复合的大小.我的jface对话框是这样的,它有一个滚动的复合,其中包含一个复合.在主要复合材料中我有3个其他复合材料,我必须实现这个功能,所以如果我将动态窗口小部件添加到复合材料中它可能会扩展,但它不应该重叠现有复合材料,而应该相应地调整其他复合材料.我应该能够按下按钮处理这些小部件.有没有人试过这个动态添加和删除小部件之前,我是swt,jface的新手.所以,任何人都可以在这里分享他们的经验,我发布了我尝试过的代码.
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class DynamicDialog extends Dialog {
private Text text;
private Text text_1;
private Composite composite;
/**
* Create the dialog.
* @param parentShell
*/
public DynamicDialog(Shell parentShell) {
super(parentShell);
}
/**
* Create contents of the dialog.
* @param …Run Code Online (Sandbox Code Playgroud) 我想以编程方式为 ComboViewer 设置一个值。我正在尝试从对象中获取值并通过使用 setSelection(Iselection) 以这种方式设置它viewer.setSelection(new StructuredSelection(Object) ,但该值未在 ComboViewer Selection 上更新。任何人都可以帮助我吗如何以编程方式设置 ComboViewer 的选择?
我试图自动换行该文本,但它没有换行。我正在尝试使用下面的代码,不确定代码有什么问题。这是
protected Control createContents(Composite parent){
Composite composite = new Composite(parent, SWT.WRAP);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(SWT.HORIZONTAL, SWT.TOP, false, false));
Group group = new Group(composite, SWT.NONE);
group.setText("my group");
group.setLayout(new GridLayout(2, false));
group.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Button button = new Button(group2,SWT.CHECK);
GridData data = new GridData(SWT.HORIZONTAL, SWT.TOP, false, true, 1, 1);
button.setLayoutData(data);
Label label= new Label(group, SWT.WRAP);
data = new GridData(GridData.FILL_HORIZONTAL);
label.setLayoutData(data);
label.setText("my long text is very long, I need to wrap this very long text lalalalalalalalalalalalalala");
}
Run Code Online (Sandbox Code Playgroud)