我已将我的 CComboBox 声明如下:
final CCombo combobox= new CCombo(shell, SWT.BORDER);
combobox.setBounds(30, 22, 88, 21);
ResultSet result = statement.executeQuery();
我想将类 myCombo 的对象添加到组合框
while(result.next())
{
String ProName=result.getString(1);
String ProId=result.getString(2);
myCombo comboItem=new myCombo(ProId,ProName); //OBJECT comboItem
combobox.addElement(comboItem); //ERROR The method addElement(myCombo)
is undefined for the type CCombo
}
组合框中的错误。addElement (comboItem) .... 但 addElement() 已在 CCombo 中定义。
这是类 myCombo
class myCombo{
private String ProId;
private String ProName;
public myCombo(String ProId, String ProName) {
this.ProId=ProId;
this.ProName=ProName;
}
public String getProductName() {
return ProName;
}
public String getProductId() {
return ProId;
}
@Override
public String toString() {
return ProName;
}
}
如何取回选中的数据。
将错误显示为不能
combobox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
myCombo item = (myCombo) combo.getItem(getSelectionIndex()) ; //ERROR
if (item!=null) {
System.out.printf("You've selected Product Name: %s, Product ID: %s%n",
item.getProductName(), item.getProductId());
}
}
});