首页 > 解决方案 > 在java打印票中格式化文本

问题描述

在 LOG 中打印 设置文本 TEXBOX

你好,我有以下问题,我正在尝试打印一张票,在打印时LOG它显示一切都很好,但是当我将字符串传递给文本字段时,这种格式会丢失,我会留下一个例子

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

标签: javaprintingformat

解决方案


问题是您在文本字段和日志中使用不同的字体,

LOG 中的字体对每个字母使用相同的空间,而文本字段则不使用


推荐阅读