我已声明我的CComboBox如下:
final CCombo combobox= new CCombo(shell, SWT.BORDER);
combobox.setBounds(30, 22, 88, 21);
ResultSet result = statement.executeQuery();
我想将类myCombo的对象添加到combobox
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
}
组合框中出错。
add元素
(组合项)。。。。但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;
}
}
如何取回选定的数据。
将ERROR显示为铁路超高
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());
}
}
});