format text in java print ticket

print in LOG SET TEXT TEXBOX

Hello, I have the following problem, I'm trying to print a ticket, when printing in the LOG it shows everything well but when I pass the string to a text field this format is lost, I'll leave an example

    double total = 0;
    f.format("%-15s %5s %10s\n", "Item", "Qty", "Price");
    f.format("%-15s %5s %10s\n", "----", "---", "-----");
    for (Detalle detalle: results) {
        f.format("%-15.15s %5d %10.2f\n", detalle.getItem(), detalle.getCantidad(),(double) detalle.getValor());
        total += detalle.getValor();
    }
    f.format("%-15s %5s %10.2f\n", "Tax", "", total * 0.06);
    f.format("%-15s %5s %10s\n", "", "", "-----");
    f.format("%-15s %5s %10.2f\n", "Total", "",
            total * 1.06);

    msg = f.toString();
    System.out.print(f);
    System.out.print(msg);
    textImprimir.setText(f.toString());

Upvotes: 0

Views: 789

Answers (1)

Axel M
Axel M

Reputation: 371

The problem is that you use different fonts in the textfield and the LOG,

The font in the LOG uses the same space for every letter, the textfields ones doesn't

Upvotes: 1

Related Questions