[英]How to display data to a JtextArea in java with exact text alignment same from the txt file
When I append the data to the JTextArea in Java it does not copy the alignment.当我 append 数据到 Java 中的 JTextArea 时,它不会复制 alignment。
There could be 2 problems at hand.手头可能有2个问题。 If your original textfile is using Tabs instead of spaces to align its columns the way it does, you need to set the same tab size on your
JTextArea
component.如果您的原始文本文件使用制表符而不是空格来对齐其列,则需要在
JTextArea
组件上设置相同的制表符大小。
See JavaDoc for setTabSize(int)请参阅JavaDoc 了解 setTabSize(int)
Secondly, alignment can only really be achieved with a mono-sapced font (where every character has the same visual width).其次,alignment 只能使用单字字体(每个字符具有相同的视觉宽度)才能真正实现。
See JavaDoc for setFont(Font)请参阅JavaDoc 了解 setFont(Font)
I just found this answer by Guillaume Polet where he describes the way to get a general-purpose monospace font by simply specifying monospaced
as the font's name:我刚刚找到了 Guillaume Polet 的答案,他在其中描述了通过简单地将
monospaced
指定为字体名称来获得通用等宽字体的方法:
JTextArea textArea = new JTextArea(24, 80);
textArea.setFont(new Font("monospaced", Font.PLAIN, 12));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.