且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Jtable中的行中添加边框?

更新时间:2022-10-23 10:07:13

你有正确的想法,你需要在cellrenderer中的标签上设置边框,具体取决于它在表格中的位置(即边缘,中心等)。 / p>

看看 matteborder 。您可以指定沿宽度和颜色绘制边框的区域。


I have a Jtable and I want to highlight a row by adding a border to the row. I have extended a DefaultTableCellRenderer and I figure the work needs to be done in the getTableCellRendererComponent method.

I'm guessing that since there doesn't seem to be a concept of a row that I need to create a custom border for the individual cells in the row. Something like a left side, top, and bottom for the first cell, a top and bottom for all the inner cells, and a top, bottom, and right side for the last cell in the row. I'm having problems finding out how to go about actually executing the thought process. I'm not sure how to use the setBorder() method or if that's even the direction I need to take.

You have the correct idea in mind, you will need to set the border on the label in the cellrenderer depending on where it is in the table(i.e. edge, center etc).

Take a look at matteborder. You can specify which areas to draw a border along w/ width and color.