0
我需要一些帮助,我是新来的java,所以可能我将不得不改变很多东西。我有这样的结果:如何用3列(Java)创建Arraylist?
[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());
}
}
}
}
他想要一个矩阵而不是一个简单的列表 – Dici
这听起来像你应该创建一个新的类型来表示这三个值的组合......(我们现在还不能确切地说出他们此刻的含义......) –