• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I print outputs to be in a table format?  RSS feed

 
Anthony Camp
Greenhorn
Posts: 5
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Title pretty much says it all. I had questions on a different thread with a project that I was working on and I have finished it with your help, now I am just wondering about the format of the outputs. I just made this thread to clean it up a bit. Right now I just have the outputs like this..



 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use fixed width fonts like system font, use HTML if you can, use a table.

You cannot easily output standard fonts to the screen in a well formatted way.
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Columnar output is hard to do with simple calls to println and printf, but you can have some limited success with tabs. This code:


produces this output:

on my console. Yours may differ.

Another approach is to format your data for a word processor where the tabs are set in the document, but you either need some detailed specs on how to create a document your word processor can handle, or an API that can help you. If you want to explore that route, consider Rich Text Format. (Some people would say you ought to look at PostScript, but they use emacs, so we do not care what they think. )

If/when you are ready to try Swing or another GUI library, there are some options there that will help you.

For the most part, Les is right: it's very hard to achieve tabular output to a console unless you used a fixed-width font.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, back in the day I remember writing complicated methods to emit tabular output using +--------+ and pipe characters (|).
 
Carey Brown
Saloon Keeper
Posts: 3312
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Adjust column widths for maximum data width. Add a header.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!