Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DefaultMutableTreeNode cannot regain focus on the second click

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application that has a JTree, there are a couple of DefaultMutableTreeNode's in there
When a node is selected, a JDialog is dispatched. After the JDialog is disposed,
I click on the same item again. But the same JDialog
doesn't reappear again. I have to choose another item and click back
on that one in order to dispatch the same JDialog again and so on so forth.

I know there is got to be something to do with

But just don't know how


 
K. Tsang
Bartender
Posts: 3496
14
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then maybe disposing it is not the right approach. Try hiding it.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Then maybe disposing it is not the right approach. Try hiding it.


No, it doesn't do the trick.
The problem I am having is When I click it the second time,
there is no response to that click.
The program stays as it is.
Thanks
Jack
 
Maneesh Godbole
Saloon Keeper
Posts: 11085
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I click on the same item again. But the same JDialog
doesn't reappear again.

Thats because the selection doesn't change.
Solution: Clear the selection (search the API docs for methods which will let you do this) after you display the dialog
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
I click on the same item again. But the same JDialog
doesn't reappear again.

Thats because the selection doesn't change.
Solution: Clear the selection (search the API docs for methods which will let you do this) after you display the dialog


Oh, tree.ClearSelection, as simple as this. Thanks
Jack
 
Maneesh Godbole
Saloon Keeper
Posts: 11085
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Most of the stuff is already in place. As a developer, it is always a good idea to refer to the API docs when you are stuck on something.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic