0
Я полный новичок в Java Basic и имею проблему с getSelectedItem(). Тот же вопрос отвечал раньше, но он не может помочь решить мою проблему, как Eclipse, всегда возвращается:Метод getSelectedItem() не определен для типа Combo
Метод getSelectedItem() не определено для типа Combo
Мой полный код:
public class FormObjects {
protected Shell shell;
private Text txtComboBoxItem;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
FormObjects window = new FormObjects();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
Combo comboOne = new Combo(shell, SWT.NONE);
comboOne.setItems(new String[] {"C Sharp", "Java", "PHP", "Visual Basic", ".NET"});
comboOne.setBounds(30, 50, 91, 23);
Button btnComboBox = new Button(shell, SWT.NONE);
btnComboBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String itemText = (String)comboOne.getSelectedItem();
txtComboBoxItem.setText(itemText);
}
});
btnComboBox.setBounds(147, 48, 130, 25);
btnComboBox.setText("Get Drop Down Item");
txtComboBoxItem = new Text(shell, SWT.BORDER);
txtComboBoxItem.setBounds(304, 50, 101, 21);
}
}
Что такое «тип Combo»? –
Это было бы потому, что, насколько я могу судить, 'Combo' не имеет метода getSelectedItem (см. [JavaDocs] (http://help.eclipse.org/juno/index.jsp?topic= % 2Forg.eclipse.platform.doc.isv% 2Freference% 2Fapi% 2Forg% 2Feclipse% 2Fswt% 2Fwidgets% 2FCombo.html)) – MadProgrammer
@HovercraftFullOfEels Я предполагаю 'org.eclipse.swt.widgets.Combo' на основе использования 'Shell' ... – MadProgrammer