This week's book giveaway is in the Other Open Source APIs forum. We're giving away four copies of Storm Applied and have Sean Allen, Peter Pathirana & Matthew Jankowski on-line! See this thread for details.
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 <-> ?
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!
There are no new questions, but there may be new answers.
Sabine El Rassy
Joined: Jan 23, 2012
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?
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.
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.