像这样我可以从 ComboBox 输出选定的值..
public static String selectedString(ItemSelectable is) {
Object selected[] = is.getSelectedObjects();
return ((selected.length == 0) ? "null" : (String)selected[0]);
}
public static void main(String[] args) {
// Add ActionListener
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
ItemSelectable is = (ItemSelectable)actionEvent.getSource();
String name=selectedString(is);
System.out.println(name);
}
};
// Add Actionlistener to ComboBox kundeAuswahl
kundeAuswahl.addActionListener(actionListener);
// i wanna have the value of name for use here:
// String test[] = getChildAsArray("kunde","projekt",name);
}
但是我想从这个函数中获取值名称,通常我使用 return,但这给了我一个错误。那我该怎么做呢?