Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我认为截图值得几段
我能想到的最好方法是检查字符串的长度并取决于 give/take \t,但这似乎不优雅。有没有更简单/更好的方法?
\t
我会为此使用 JTable。您可以将一个放在 JScrollPane 中。这将使您自动对齐列。另外,您将获得列标题,这将有助于理解数据的含义。
如果您想坚持使用纯文本并对字段长度设置上限(您需要保证对齐),那么您可以使用 printf。