Its unfortunately that Java Swing does not include a feature to show the line number for each row on a JTable. This would be similar to the line numbers shown in a spreadsheet application. Fortunately, Swing’s flexibility and extensibility allows us to create one with ease.

Most of the solutions out there are based on using two tables side-by-side. One to represent the main table and the other to display the line numbers. There are event handlers listening on the main table to update the line number table.
I present another solution which is based on a single JComponent that will render the line numbers. This is lighter and more easily customizable in case you need to add additional features or behaviors.




Using the power of Java2D, I was able to create more advance and stylish borders. Using a combination of a round rectangle and a triangle shape, I created the callout border shown on the left. This is also very similar to the balloon tips on the Windows OS. Decorate a JLabel with a callout border and you got an awesome tooltip replacement.