This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Jtable mouse header cursor  RSS feed

 
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
 
Bartender
Posts: 5167
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?


 
Rancher
Posts: 2934
19
  • 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: 5167
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 =)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!