0
Le travail d'impression n'imprime qu'une seule ligne à partir de JTable
. Seulement obtenir une sortie en entrant une ou plusieurs rangées:Java Swing Invoice String.format renvoyant uniquement la valeur() {} à JTextPane?
public void invoice_job() {
try {
int rows=JTable.getRowCount();
for (int row = 0; row<rows; row++) {
Names = (String)JTable.getValueAt(row, 0);
Quanti = (String)JTable.getValueAt(row, 1);
Prices = (Double)JTable.getValueAt(row, 2);
String head = String.format("%30s\n\n", " Invoice Reciept ");
String s = String.format("%-15s %5s %10s\n", "Item", "Qty", "Price");
String s1 = String.format("%-15s %5s %10s\n","---------","--------"," ----------");
String line = String.format("%-15s %5s %10.2f\n",Names,Quanti,Prices);
String lin2 = String.format("%-15s\n","-------------------------------------");
String Total = String.format("%37s\n","Total");
String total = String.format("%37s\n\n",lbl.getText());
String footer = String.format("%-15s\n", "Meridon sweets and bakers\nSince 1987\nPoint of sale system\nPowered by msofttech\nwww.msofttech.net");
String output = head + s + s1 + line + lin2 + Total + total + footer;
textPane.setText(output);
textPane.setText(output);
textPane.setText(output);
textPane.setText(output);
JOptionPane.showMessageDialog(null, output);
}
PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printerJob.defaultPage();
Paper paper = new Paper();
paper.setSize(180.0, (double) (paper.getHeight() + rows * 10.0));
paper.setImageableArea(rows, rows, paper.getWidth() - rows * 2,
paper.getHeight() - rows * 2);
pageFormat.setPaper(paper);
pageFormat.setOrientation(PageFormat.PORTRAIT);
printerJob.setPrintable(textPane.getPrintable(null, null), pageFormat);
printerJob.print();
}
catch (Exception e) {
e.printStackTrace();
}
entrée:
entrée sont 2 éléments.
sortie:
sortie est un seul élément.