• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..



 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, back in the day I remember writing complicated methods to emit tabular output using +--------+ and pipe characters (|).
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adjust column widths for maximum data width. Add a header.
 
reply
    Bookmark Topic Watch Topic
  • New Topic