【发布时间】:2014-09-09 16:04:33
【问题描述】:
我正在尝试在 JFace 对话框的 TitleAreaDialog 中创建一个组合框。 在下面的代码中,我要求用户输入高度和宽度的值,并且用户必须从组合框中选择线条强度(不可编辑)。这将是 1、2、3 或 4。这是我目前所拥有的:
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class RectDialog extends TitleAreaDialog {
private Text txtWidth;
private Text txtHeight;
private Text txtLineStrength;
private String width;
private String height;
private String lineStrength;
public RectDialog(Shell parentShell) {
super(parentShell);
}
@Override
public void create() {
super.create();
setTitle("New Rectangle");
// setMessage("", IMessageProvider.INFORMATION);
}
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout(2, false);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
container.setLayout(layout);
createWidth(container);
createHeight(container);
createLineStrength(container);
return area;
}
private void createLineStrength(Composite container) {
// TODO: Create line strength
}
private void createHeight(Composite container) {
Label lbtHeight = new Label(container, SWT.NONE);
lbtHeight.setText("Height");
GridData dataHeight = new GridData();
dataHeight.grabExcessHorizontalSpace = true;
dataHeight.horizontalAlignment = GridData.FILL;
txtHeight = new Text(container, SWT.BORDER);
txtHeight.setLayoutData(dataHeight);
}
private void createWidth(Composite container) {
Label lbtWidth = new Label(container, SWT.NONE);
lbtWidth.setText("Height");
GridData dataWidth = new GridData();
dataWidth.grabExcessHorizontalSpace = true;
dataWidth.horizontalAlignment = GridData.FILL;
txtWidth = new Text(container, SWT.BORDER);
txtWidth.setLayoutData(dataWidth);
}
@Override
protected boolean isResizable() {
return true;
}
private void saveInput() {
width = txtWidth.getText();
height = txtHeight.getText();
// lineStrength = txtLineStrength.getText();
}
@Override
protected void okPressed() {
saveInput();
super.okPressed();
}
public String getWidth() {
return width;
}
public String getHeight() {
return height;
}
public String getLineStrength() {
return lineStrength;
}
}
我现在卡在 createLineStrength() 方法上。如何输入一个组合框,然后读取 getLineStrength() 中的值?
【问题讨论】: