java - 在java打印票中格式化文本
问题描述
你好,我有以下问题,我正在尝试打印一张票,在打印时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());
解决方案
问题是您在文本字段和日志中使用不同的字体,
LOG 中的字体对每个字母使用相同的空间,而文本字段则不使用
推荐阅读
- swiftui - 如何将对象绑定中的属性作为正常状态变量传递给子视图
- vue.js - 如何在 Vue.js 中为多个角色和用户创建登录名
- sass - 有没有办法在 Nuxt.js 中使用 sass 而不是 node-sass(sass-loader 的默认值)?
- database - 是否可以在 casssandra 中存储逗号分隔值
- ruby - 如何将base64编码文件传递给ruby irb中的http post请求?
- node.js - Windows 上的 Node.js 和堆内存不足
- python - 如何在pyspark中的两列上执行有效的连接
- java - 如何排列文件夹中的 mp4 文件列表?
- c++11 - 无法取消引用泛型迭代器类型
- c++ - 运行 DX9 程序时出错