Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Deselect nodes in JTree when user clicks empty surface  RSS feed

 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to deselect all nodes in JTree when I click on empty surface in it? I know that

is used for deselecting all nodes, but how can I know that user clicked on an empty surface?
 
Stanislav Lapitsky
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:Is there a way to deselect all nodes in JTree when I click on empty surface in it? I know that

is used for deselecting all nodes, but how can I know that user clicked on an empty surface?


What o yu mean by the "empty surface"? Space below all the nodes?
tree has getRowCount() and Rectangle getRowBounds(int row) methods. So you can get rectangle of the last row and compare your event's y coordinate with the rectangle. If the y is bigger than rect.y+rect.height you clicked on empty space.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to complicate things and figure out the rectangles.

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about the 'empty space' to the right and left? This is hackish (anything involving Robot is hackish ), but does take care of that.

edit NVM the class name, it was originally created for some other thread
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:No need to complicate things and figure out the rectangles.



This works perfectly! Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!