Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1680
  • Last Modified:

How to draw an optional border around a JTable row?

How would I go about drawing a border around a row in a JTable?  The default behaviour is cell based, I don't want to see the cell borders but I do want an optional border around a row.  I have been able to make the cell borders disappear but have not been able to figure out how to get a border around the entire row.

At the moment I am considering providing custom cell renderers to draw the top and bottom borders and depending on the column draw either the left or right border.  In other words draw the border in parts.

I don't like this solution and am wondering if there is a better easier way...
0
macgre
Asked:
macgre
  • 5
  • 4
  • 3
  • +1
2 Solutions
 
CEHJCommented:
I would pursue the way you've already identified
0
 
CEHJCommented:
There is no concept of a row at the view level really - only a succession of cells
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
zzynxSoftware engineerCommented:
>> I would pursue the way you've already identified
>> There is no concept of a row at the view level really - only a succession of cells
I agree
0
 
macgreAuthor Commented:
objects,

If I understand your code correctly you are expanding the insets object of a cell to encapsulate a selected block of cells.  I was to use the code from the page you listed because there were three imports not included in the page, so I couldn't do my own testing...

I have a list of people where some may be "special" and my client wants me to draw a red border around them, they did not like it when I showed them each cell with a red border...  Your solution seems tied to a selection, I would like to test if I can have multiple, non-continuous rows with a red border.

I may end up doing a combination of both, that is a custom renderer that uses an insets object to draw a border around the entire row, getting its dimensions from the viewport width and row height.
0
 
macgreAuthor Commented:
I went with a custom renderer, it wasn't as hard as I thought it would be...
0
 
CEHJCommented:
:-)
0
 
objectsCommented:
> I was to use the code from the page you listed because there were three imports not included in the page, so I couldn't do my own testing...

they are also there

http://www.objects.com.au/java/examples/swing/table/BorderCellRenderer.java
http://www.objects.com.au/java/examples/swing/table/CellBorder.java

> that is a custom renderer that uses an insets object to draw a border around the entire row, getting its dimensions from the viewport width and row height.

which is what the example I posted above already does :)
0
 
objectsCommented:
So not exactly clear why you ignored my comment which gave you an example of what you mentioned trying, and instead accepted comments that just agreed with you without providing any material that would actually help.
guess I should have said, "I agree, heres some code to get you started" :-D
0
 
zzynxSoftware engineerCommented:
Thx
0
 
macgreAuthor Commented:
objects,

Did not intend to offend, I could not get your example to work so I went with my original idea.  I tried to incorporate what I saw in your code but couldn't get the results I wanted.  In the end I built three different renderers, one for each edge and one for the middle and used the column index to decide which one to use.  I extended DefaultCellerRenderer and overrode the paintBorder method of the LineBorder class three times (called LEFT, MIDDLE and RIGHT) and used the appropriate one from the getTableCellRendererComponent.  Since this looks nothing like what you provided, I couldn't see how I could take points away from those that suggested that my original plan was the correct one.

I will take what you have given and try again later, if I can get it working and it is an improvement over what I have now I will post a question directed at you personally and reward you for your efforts.  I do appreciate your help, you have been very helpful in the past and I do appreciate your input, I just couldn't use it this time...
0
 
objectsCommented:
I suggested ujsing a custom cell renderer as you were also considering, and gave u an example of such. Just fail to see how that is less helpful than someone simple posting "I agree".

> I extended DefaultCellerRenderer and overrode the paintBorder method of the LineBorder class three times (called LEFT, MIDDLE and RIGHT) and used the appropriate one from the getTableCellRendererComponent.

what i posted does basically the same thing, just improves on that a little by delegating the painting of the border (to avoid having to override).

Will just agree with you next time ;)
0
 
macgreAuthor Commented:
It seems I didn't understand your code as well as I thought, not being it to get it to run didn't help either, still I prefer to have code to test with than not ;-)
0
 
macgreAuthor Commented:
Couple of questions:

1) The JTable renders each cell separately, does your example draw the row border once for every cell in the table?

2) Your solution seemed tied to a selection I would need something that draws a border based on data associated with the row but not displayed.  I have an object that supplies data to the table, but there are additional attributes that are not being displayed but would cause the row border to be red.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now