0

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

David Gidony
  • 1,243
  • 3
  • 16
  • 31

2 Answers2

1

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.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • I know this example, It really helped me to accomplish what I did so far, but it will not answer my question, I need to try to add the borderlines in my current coding. – David Gidony Dec 18 '14 at 08:03
  • 1
    @DavidGidony It answers the question. You need a custom renderer for Borders around cells in the row header. I showed how to create a custom renderer using a JTable. It is easy to modify and change the Border. `I need to try to add the borderlines in my current coding.` If you want to continue to use a JList then you need to create a custom renderer for the JList. Read the JList API and follow the link to the Swing tutorial on "How to Use Lists" to find an example or you can search the forum. So, either modify your code to use a JTable, or change your code to add a custom renderer. – camickr Dec 18 '14 at 15:51
0

finally found what I was looking for here :

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

thanks !

Community
  • 1
  • 1
David Gidony
  • 1,243
  • 3
  • 16
  • 31