Column delimiters in JTable or JXTable

I have a JTable (or JXTable, to be more precise) with three sections of grouped columns that I want to split. I had 3 tables that I programmatically linked (scrollbar position, sort, select). I used a lot of code to link this, and I want to get rid of this. Now I switch to 1 JXTable, because there is something nicer in this table class.

I found some (not very satisfactory) solutions to almost the same problem. Maybe someone has a good suggestion for me.

Option 1: an empty column as a separator (another color, for example, gray) and programmatically jump over this empty column when using arrows or tabs.

option 2: setting the field for only 1 side of 1 column for a larger size, so it looks like a separator. So far, I have only learned how to set fields for all columns

option 3: back to 3 separate tables again (especially for sorting tables in the same way - this is a lot of work because I don’t want to repeat columns in separate sections). This means that I have to rewrite the table sorter, sorting by an invisible column.

any suggestion is welcome (also if it has none of the three given parameters)

+3
source share
1 answer

I did something similar to what you are doing by overriding the rendering of the cells in the third column to have a tight right border and no other borders. You can do the same in the column heading of the table so that the border expands there. It clearly places the border inside the cell, but that might be enough for you.

{ .... table.getColumnModel().getColumn(2).setCellRenderer( new ThickRightBorderCellRenderer()); .... } private static class ThickRightBorderCellRenderer extends DefaultTableCellRenderer { @Override public Border getBorder() { return BorderFactory.createMatteBorder(0, 0, 0, 3, Color.BLACK); } } 

Example

+4
source

Source: https://habr.com/ru/post/1306575/


All Articles