I am doing project on printing a passbook of bank in which i have 8 fields those are transactiondate,
particulars,chequeno,debit,credit,balance,print and serialno and i wanted to print that in passbook and print is a boolian type if i mark on one row it must print the other rows present in that table can any one help me.

Dani AI

Generated

Brief, practical guidance for (and to correct the unhelpful quips from and ): printing a selected set of rows from a Swing table for a passbook printer is best solved in one of three ways depending on how much control the printer needs.

Option 1 — quick: build a temporary TableModel containing only rows where the boolean "print" column is true and call JTable.print(), which handles pagination and headers. Example (copy rows into a DefaultTableModel and print the temporary table):

DefaultTableModel src = (DefaultTableModel) originalTable.getModel();
DefaultTableModel tmp = new DefaultTableModel();
for (int c=0; c<src.getColumnCount(); c++) tmp.addColumn(src.getColumnName(c));
for (int r=0; r<src.getRowCount(); r++) {
    Object flag = src.getValueAt(r, printColIndex);
    if (Boolean.TRUE.equals(flag)) {
        Vector row = new Vector();
        for (int c=0; c<src.getColumnCount(); c++) row.add(src.getValueAt(r,c));
        tmp.addRow(row);
    }
}
JTable printTable = new JTable(tmp);
printTable.print();

Option 2 — precise layout: implement Printable and use PrinterJob when column widths, fonts, or continuous passbook paper must match exactly. The Printable implementation draws text with Graphics2D, computes line height from FontMetrics, paginates rows, and uses Paper/PageFormat to set imageable area.

Option 3 — raw device control: if the passbook printer expects ESC/POS or manufacturer-specific commands, send raw bytes with javax.print (DocFlavor.BYTE_ARRAY.AUTOSENSE and SimpleDoc) to the target PrintService. This requires the printer manual and exact command sequences.

Troubleshooting notes: test layout by printing to PDF first; run printing off the EDT (SwingWorker or background thread); verify the "print" column contains true Booleans; set Paper size and imageable area to match the passbook; and test on the real hardware—many problems are printer-protocol or margin-related rather than Swing code.

Recommended Answers

All 3 Replies

Given your description (the lack of description that is), you may use a System.out.println.

commented: uppity since this kid down voted +4

i want to print that in passbook printer m/c

Again, refer to javaaddict's post for more information on why nobody is helping you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.