• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable mouse header cursor

 
Sabine El Rassy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

when the mouse cursor is over the boundary between the headers of two adjacent columns in a jtable, it changes to a double headed arrow, indicating that the column width can be changed by dragging the mouse. How can I put a listener that tells me when the mouse icon has changed from a simpe mouse pointer to a double headed arrow <-> ?
Thanks
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This begs the question: how do you intend to use that information? I ask because I believe there may be (probably is) a better way of achieving that than this approach.

And welcome to the Ranch!
 
Sabine El Rassy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
I need to do like excel, when the user double click on the header while its double headed arrow, the column width will take its max value.
I have done this , but Im just wondering If there's some other way?


 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I put a listener that tells me when the mouse icon has changed from a simpe mouse pointer to a double headed arrow


I don't think there is an event for this, but you can check to see which cursor is displayed when the mouse click event is generated.

Here is my solution that uses this approach. To resize the row you use a double click. Note, the code appears more complicated because it will also handle the situation where a sorter is being used on the table. That is, when you click in the resizing area, sorting on the row will NOT be invoked.



Note: the above code uses the Table Column Adjuster class to determine the maximum width of the column.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would recommend a MouseListener added to the table header with its mouseClicked(...) code something likeFor your original approach, you could extend JTableHeader and override getCursor() to call firePropertyChanged("cursor") whenever the cursor changesAnd listen for the property changeI wouldn't recommend this as it involves extending a core class -- which is avoidable by adopting the MouseListener approach.
edit: and requires still more code to determine which column to resize.
 
Sabine El Rassy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried both methods and it works! thanks =)
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic