【发布时间】:2015-09-05 21:16:09
【问题描述】:
我需要一些帮助,我是 java 新手,所以可能我需要更改很多东西。我得到了这个结果:
[Goya, Scoop 2000 W, 123]
如果我尝试添加更多,它会显示:
[HMI, Scoop 2000 W, 123]
[HMI, Scoop 2000 W, 123, Fresnel, Set light 1000 W De Sisti, 124]
[HMI, Scoop 2000 W, 123, Fresnel, Set light 1000 W De Sisti, 124, Goya, Set light 1000 W De Sisti, 456]
而我真正需要的是这样的:
[HMI, Scoop 2000 W, 123,]
[Fresnel, Set light 1000 W De Sisti, 124]
[Goya, Set light 1000 W De Sisti, 456]
这是我的代码:
Component[] componente = painelMain.getComponents();
list = new ArrayList();
for (int i = 0; i < componente.length; i++) {
if (componente[i] instanceof JTextField) {
JTextField textfield = (JTextField) componente[i];
if (!"".equals(textfield.getText())) {
list.add(textfield.getText());
System.out.println(list);
}
} else if (componente[i] instanceof JComboBox) {
JComboBox combo = (JComboBox) componente[i];
if (!"".equals(combo.getSelectedItem())) {
list.add(combo.getSelectedItem());
}
}
}
}
【问题讨论】:
-
他想要一个矩阵而不是一个平面列表
-
听起来你应该创建一个新类型来表示三个值的组合......(我们目前无法真正说出它们的含义......)
标签: java multiple-columns