0

I have a JTable in a JScrollPane. When the user is at the top of the table, eg. row 0 is displayed and above it the table header tableHeader.contains(p); is true.

When the user scroll down and say row 10 is now the top row, if the mouse is over the table header and the table header changes its look due to that, tableHeader.contains(p); is false in all cases.

How can I detect that the mouse cursor is over the header when the top row is not row 0?

beginner_
  • 7,230
  • 18
  • 70
  • 127
  • How can I detect that the mouse cursor is over the header when the top row is not row 0?, please how to corresponding words from 1st and 2nd part together, can be miss_spelled as non_sence, edit your question here with better description – mKorbel Jan 09 '14 at 10:49
  • 1
    post an SSCCE short, runnable, compilable with hardcoded value for JTables view in local variable, maybe is issue somewhere, not only as is described in (partial) answer by @Sam here – mKorbel Jan 09 '14 at 10:51
  • A complete example is examined [here](http://stackoverflow.com/q/7137786/230513). – trashgod Jan 09 '14 at 13:41

1 Answers1

2

Use

table.getTableHeader().addMouseListener(...)

to add a MouseListener to the table header. The MouseListener has a method

mouseEntered(MouseEvent e)

in which you can put the code you want to be executed when the cursor is over the table header.

Sam
  • 253
  • 1
  • 9