-2

Possible Duplicate:
Find the JTable cell and paint it

This is my Rectangle class object.

 Rectangle cell = table.getCellRect(row, column, false);

Now I want to highlight it on mouse press event and again back to normal to mouse realeased event.

Community
  • 1
  • 1
Java_Alert
  • 1,159
  • 6
  • 24
  • 50
  • 3
    I'm not able to see any difference betweens your last question, yes is possible (`Can i do the same without user interaction of that particular table means on clicking of something else?`), this is basic properties of XxxCellRenderer, no idea where your question goes – mKorbel Jan 10 '13 at 08:17
  • *"I want.."* a question, and no. Adding a '?' to the end of a specification or instruction, does not make it a question. What is your question? – Andrew Thompson Jan 10 '13 at 08:17
  • @mKorbel Thanks for your guidence, will follow that surely. – Java_Alert Jan 10 '13 at 11:02
  • @AndrewThompson Thanks for your attention.I have done the required changes. – Java_Alert Jan 10 '13 at 11:03

1 Answers1

4

There are multiple ways to add the feature.

The first one is implementing custom Renderer/Editor for the cell. The renderer keeps row/column and isPressed state. When mouse is pressed renderer state is set and reset on release.

Another way is to override JTable's paintComponent() method to draw the Rectangle with e.g. semi-transparent color.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • 3
    Or use SwingX's highligher API – MadProgrammer Jan 10 '13 at 08:52
  • nitpicking again: the renderer mustn't _keep_ state - it queries the state and temporarily (per-cell) configures itself accordingly. You and me know that, newbies might not yet :-) Plus, paintComponent in a table is extremely rarely tweaked. – kleopatra Jan 10 '13 at 11:39