0

I need your help guys. I am currently working on a simple JTable in Java with 3 Columns and 128 rows. Now there is one problem i cannot solve at the moment. The thing i want is that when I click on a single cell it changes its background color to Green.

So i need to implement a MouseListener which reacts to the selected cell and sets its background to green. Sort of a "CellListener" I mean.

I've tried so many things and searched many blogs etc. but none of them gave me a satisying answer.

Do you have any tips for me?

Lukas
  • 1
  • 1
    `when I click on a single cell it changes its background color to Green.` - does it change color permanently? Or does it change back to its regular color when you click on a different cell? – camickr Oct 05 '16 at 16:02
  • For [example](http://stackoverflow.com/a/12352838/230513). – trashgod Oct 05 '16 at 18:06
  • it changes its color back when I click on a different cell, but i want that the cell keeps the color permanently – Lukas Oct 06 '16 at 11:07

1 Answers1

0

I doubt you will find a direct link between you being able to click on the table and it respond. Because JTables aren't going to listen out for it like that. If you want to do this. You will need an intermediate step. I would suggest that you use the mouse listener to get the mouse location on the screen when the user clicks. And then check IF that location is the same as a particular cell of the JTable.

SuperHanz98
  • 2,090
  • 2
  • 16
  • 33