Draw Row Lines on the Jtable RowHeaders in hava

672 Views Asked by At

I have this JTable,with a row header (on the left - painted in pink). how can I set border lines between them ?

ive tried the setborder method , but it only sets the outer border, I need the space between them - just like in the upper column headers.

how can I accomplish that ?

EDIT: this is the code for the row headers:

static String[] rowHeaders = {
        "mc 01", "mc 02", "mc 03", "mc 04", "mc 05",
        "mc 06", "mc 07", "mc 08", "mc 09", "mc 10", "mc 11", "mc 12",
        "mc 13", "mc 14", "mc 15", "mc 16", "mc 17", "mc 18", "mc 19",
        "mc 20", "mc 21", "mc 22", "mc 23", "mc 24", "mc 25", "mc 26",
        "Nitris 01", "Nitris 02", "Sound A", "Sound B", "Sound C" };

JList rowHeader;

// CREATING A ROW HEADER 
ListModel lm = new AbstractListModel() {

      public int getSize() 
      {
        return rowHeaders.length;
      }

      public Object getElementAt(int index) 
      {
        return rowHeaders[index];
      }
    };

    rowHeader = new JList(lm);
    rowHeader.setFixedCellWidth(80);
    rowHeader.setFixedCellHeight(myTable.getRowHeight());
    rowHeader.setBackground(Color.pink);
    rowHeader.setFont(new Font("Ariel", 1, 18));
 //     rowHeader.setBorder(new LineBorder(Color.BLACK, 1));

    DefaultListCellRenderer renderer =  (DefaultListCellRenderer)rowHeader.getCellRenderer();  
    renderer.setHorizontalAlignment(JLabel.CENTER);

    myTableScrollPane.setRowHeaderView(rowHeader);

thank you

Dave.

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

finally found what I was looking for here :

JList: How to get a LineBorder "between" cells?

thanks !

2
On

Take a look at Row Number Table. It shows how to add numbers as a row header.

The code also shows how to create a custom render to render the numbers. The supplied code used the Border of the column header, but you can change it to any Border you wish. It also shows how to highlight the row header that is currently selected, in case you want that feature.