0

I have the exact same code as this post: https://stackoverflow.com/a/8187799/5464538

This code create a table like this one:

+------+------+------+------+
|/\/\/\| col1 | col2 | col3 |
+------+------+------+------+
| row1 |      |      |      |
+------+------+------+------+
| row2 |      |      |      |
+------+------+------+------+
| row3 |      |      |      |
+------+------+------+------+

I want to be able to label the first cell of the tab. The one that contains /\/\/\, in order to give a title to the first column. I didn't find anything on my researches on such a thing. I'm not even sure if this is possible with my current JTable. If it is not, is there an other way to have this result?

Community
  • 1
  • 1
pioupiou1211
  • 353
  • 4
  • 16
  • which you want to edit is as i understand it a non existent cell – XtremeBaumer Apr 06 '17 at 14:44
  • @XtremeBaumer That's what I figured out yes. I was wondering if I could make it existent. By shifting all the rows/columns maybe? Or use a complete different `JTable`. I'm new to this so it's not very easy for me. – pioupiou1211 Apr 06 '17 at 14:48

1 Answers1

0

You can add any component to the scrollpane using something like:

scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new JLabel("Row:"));

However this will not look very good since the label will not look like the other row/column header renderers.

Instead I suggest you check out Row Number Table for a different implementation of a row header that is more flexible than what you are currently using.

In the code provided for the RowNumberTable class you will find:

column.setHeaderValue(" ");

You would need to change that statement with the text you want to see. Maybe you would customize the class to pass in a parameter containing the String to display in the header.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Thanks a lot, I'm going for your second solution! Just one problem: I can't find where (if it is possible in this implementation?) I can label the rows as I want? – pioupiou1211 Apr 06 '17 at 16:19
  • @pioupiou1211, it was not designed to provide random labels for each row. If was designed to simply display a row number as the number of rows in the table dynamically changes. If you want your current implementation, then just borrow the logic from this class that uses the table header as the "corner" component of the scroll pane. – camickr Apr 06 '17 at 16:43