Profile Picture
Zoomed image.
Some annoying EU rule forces me to tell you
we might use cookies. The funny thing is by entering
most pages, it's already too late. So completely
useless. Good job, EU
Cookies are nothing dangerous and is just a way to
store data on your machine. Otherwise, how do we
know you are you?


jTable - Make ASCII tables for your console application!

If you want a similar library for the awesome
Go programming language, check out gTable.


Makin' Tables in plain text like it's nobody's business

Ever been impressed by MySQL's console tables?
Ever been to
Want to create a Java application with these tables?
Sure, why not!


Check out PingPlus to see an open source project that uses jTable.

This documentation is one of the very few documentations I ever write.
I don't like to write documentations. But let's do it anyway!
And with a little twist. We will not just be boring and talk
functions. No no no! We will make an example! Yaaaaaaaaay

To start with our example, let's make a ping tool.
This tool will both use this library and jWebby.
It will ping multiple webpages and print out the speed of them.

Here are our plans:
  1. Make a global variable called StringTable:
    private static StringTable table;
  2. Make a main method
  3. Initiate the table: table = new StringTable();
    and add heading: table.add("URL", "Time").addRow();
  4. Make an approporite number of Java Threads to match the arguments:
    Thread[] threads = new Thread[args.length];
  5. Fill the threads in with a new function we will make later:
    for(int i = 0; i < args.length; i++)
    	threads[i] = ping(args[i]);
  6. Wait for all threads to complete:
    	for(Thread t : threads)
    catch(InterruptedException e){
  7. Add padding:
  8. Print out the table (Warning: This is very technical and is the hardest step of them all):
  9. Now let's make the ping(String url) method and make a new thread!
    public static Thread ping(String url){
    	new Thread(() -> {
  10. Get the current milliseconds:
    long millis = System.currentTimeMillis();
  11. Make a web request (Thanks jWebby):
    catch(IOException e){
    		table.add(url, "Error").addRow();
  12. Get the difference:
    double time = (double) System.currentTimeMillis() - millis;
  13. Get the best suffix:
    String ext = "ms";
    if(time > 1000){
    	time = Math.round(time / 100) / 10d;
    	ext = "s";
    String sTime = String.valueOf(time);
    if(sTime.endsWith(".0")) sTime = sTime.substring(0, sTime.length() - 2);
  14. Add the item to the table (Remember it's on a separate Thread):
    	table.add(url, sTime + ext).addRow();
  15. Let's close the thread and end the method!
    	return t;

Uhh I'm afraid we're done. That's boring!

Example images can be found on Twitter
and use an IDE with code completion if you want a way to explore the methods easily.
One more example:
Picture from Twitter