jTable - Make ASCII tables for your console application!

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

Download

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

Ever been impressed by MySQL's console tables?
Ever been to https://ozh.github.io/ascii-tables/?
Want to create a Java application with these tables?
Sure, why not!

Documentation:

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:
    try{
    	for(Thread t : threads)
    		t.join();
    }
    catch(InterruptedException e){
    	Thread.currentThread().interrupt();
    	return;
    }
  7. Add padding:
    table.paddingLeft(1).paddingRight(2);
  8. Print out the table (Warning: This is very technical and is the hardest step of them all):
    System.out.println(table);
    jk
  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 web request (Thanks jWebby):
    try{
    	Webby.get(url);
    }
    catch(IOException e){
    	synchronized(table){
    		table.add(url, "Error").addRow();
    	}
    	return;
    }
  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):
    synchronized(table){
    	table.add(url, sTime + ext).addRow();
    }
  15. Let's close the thread and end the method!
    	});
    	t.start();
    	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