喜欢我可以输出从ComboBox选择的值..获取的SelectedItem的组合框
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);
}
,但我想获得价值名出这个功能的,一般我用的回报,但这给我一个错误。那我该怎么做呢?
这样是不妥当的方式,在大多数情况下,完全正确的建议结束,但复杂错误的概念越来越多,要尽量避免,将任何图形用户界面及其监听器移到公共方法或空白处,然后这里所有的哼声都不能纠正或改变它,因为(真实的)和更好的帮助在发布[SSCCE](http://sscce.org/)简短,可运行,可编译 – mKorbel 2013-04-24 10:50:08