我正在为我的发票使用收据打印机,并参考CLOUGH先生已回复的Post并提供了WAGU库的参考,我写了所有代码,但代码在哪里
List<List<String>> t2Rows = Arrays.asList(
Arrays.asList("Optical mouse", "120.00", "20", "2400.00"),
Arrays.asList("Gaming keyboard", "550.00", "30", "16500.00"),
Arrays.asList("320GB SATA HDD", "220.00", "32", "7040.00"),
Arrays.asList("500GB SATA HDD", "274.00", "13", "3562.00"),
Arrays.asList("1TB SATA HDD", "437.00", "11", "4807.00"),
Arrays.asList("RE-DVD ROM", "144.00", "29", "4176.00"),
Arrays.asList("DDR3 4GB RAM", "143.00", "13", "1859.00"),
Arrays.asList("Blu-ray DVD", "94.00", "28", "2632.00"),
Arrays.asList("WR-DVD", "122.00", "34", "4148.00"),
Arrays.asList("Adapter", "543.00", "28", "15204.00")
);
以上代码值以字符串形式给出并修复,但我必须从jTable
添加这些值。
我从jTable
获取以下代码
for (int i = 0; i < tbl_sale.getRowCount(); i++) {
String pid = tbl_sale.getValueAt(i, 0).toString();
String item = tbl_sale.getValueAt(i, 1).toString();
String quant = tbl_sale.getValueAt(i, 2).toString();
String rate = tbl_sale.getValueAt(i, 3).toString();
String rs = tbl_sale.getValueAt(i, 4).toString();
}
但现在问题是我无法在列表Array.asList中插入这些值。 任何人都可以帮我解决这个问题。
由于
答案 0 :(得分:3)
尝试这样的事情:
List<List<String>> t2Rows = new ArrayList<List<String>>();
for (int i = 0; i < tbl_sale.getRowCount(); i++) {
String pid = tbl_sale.getValueAt(i, 0).toString();
String item = tbl_sale.getValueAt(i, 1).toString();
String quant = tbl_sale.getValueAt(i, 2).toString();
String rate = tbl_sale.getValueAt(i, 3).toString();
String rs = tbl_sale.getValueAt(i, 4).toString();
ArrayList<String> temp = new ArrayList<String>();
temp.add(pid);//example I don't know the order you need
temp.add(item);//example I don't know the order you need
temp.add(quant);//example I don't know the order you need
temp.add(rate);//example I don't know the order you need
temp.add(rs);//example I don't know the order you need
t2Rows.add(temp);
}