aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Jtable mouse header cursor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Jtable mouse header cursor" Watch "Jtable mouse header cursor" New topic
Author

Jtable mouse header cursor

Sabine El Rassy
Greenhorn

Joined: Jan 23, 2012
Posts: 10
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

Joined: May 03, 2008
Posts: 4543
    
    5

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!


luck, db
There are no new questions, but there may be new answers.
Sabine El Rassy
Greenhorn

Joined: Jan 23, 2012
Posts: 10
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

Joined: Jun 13, 2009
Posts: 2182
    
    7
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

Joined: May 03, 2008
Posts: 4543
    
    5

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

Joined: Jan 23, 2012
Posts: 10
I tried both methods and it works! thanks =)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jtable mouse header cursor