2

I am using receipt printer for my invoices, and Referring to the Post in which Mr. CLOUGH has answered and gave reference of WAGU library, I wrote all the code but where the code like

 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")
    );

in above code values are given as string and fixed, but I have to add these values from my jTable.

wherever I get values from jTable with following code

 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(); 
}

but now the problem is I am unable to insert these values in list Array.asList. Can Anyone help me through this problem.

Thanks

Community
  • 1
  • 1
mrabro
  • 1,097
  • 4
  • 13
  • 27
  • can you give a short example? – mrabro Jan 26 '16 at 21:43
  • Are you sure you are going to put the values in the correct place? Your current List contains four-item lists, while the loop seems to create five items. This may hint at a mismatch of data. – RealSkeptic Jan 26 '16 at 21:49
  • @RealSkeptic I think the code on the top isn't part of his project...probably code copied from another answer. His problem is the same but different. In this example he needs the same data structure but with different fields. Just speculating...I don't know that for sure. – brso05 Jan 26 '16 at 21:57
  • @RealSkeptic I think he wants to apply the code above to his problem in a dynamic way instead of hard coding values... – brso05 Jan 26 '16 at 21:58

1 Answers1

3

Try something like this:

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); 
}
brso05
  • 13,142
  • 2
  • 21
  • 40