• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Jtable mouse header cursor

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried both methods and it works! thanks =)
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic