[英]SWT - ComboBoxCellEditor / Default Value
我希望ComboBoxCellEditor能够有3种选择。 现在,它只有Yes或No。我希望它有Yes,No和Both。
除非单击该单元格,否则组合框选择值也不会显示在表格中。 除非他们单击空单元格,否则很难判断表单元格是否有可能进行选择。 我希望它至少显示向下箭头。
我读过一些文章,您唯一可以解决此问题的方法是设置默认值。
我不确定如何添加第三个值。 我将添加代码以尝试添加第三个值
如何在不首先单击单元格的情况下将组合框显示在表中?
。
public class OptionEditingSupport extends EditingSupport {
private ComboBoxCellEditor cellEditor;
public OptionEditingSupport(ColumnViewer viewer) {
super(viewer);
cellEditor = new ComboBoxCellEditor(((TableViewer)viewer).getTable(), new String[]{"Yes", "No", "Both"}, SWT.READ_ONLY);
}
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
protected boolean canEdit(Object element) {
return true;
}
protected Object getValue(Object element) {
return 0;
}
protected void setValue(Object element, Object value)
{
if((element instanceof AplotDatasetData) && (value instanceof Integer)) {
Integer choice = (Integer)value;
String option = (choice == 0? "Yes":"No":"Both"); **<- Error Here
((AplotDatasetData)element).setMarkupValue(option);
getViewer().update(element, null);
}
}
}
x ? y : z
是三元运算符,在内部执行以下操作:
if(x)
y;
else
z;
因此,您只能将其与三个组件一起使用。 使用的if
else if
else
来代替:
Integer choice = (Integer)value;
String option = "";
if(choice == 0)
option = "Yes";
else if(choice == 1)
option = "No";
else
option = "Both";
TableEditor
可用于在表格单元格顶部显示任何窗口小部件。 它应该通过显示Combobox来解决您的问题,让用户知道该行和该列有可能的选择。
我不确定我是否理解您关于3个选择的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.