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.
