File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to mark checked CheckBox in JTree only when user click on CheckBox? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to mark checked CheckBox in JTree only when user click on CheckBox?" Watch "How to mark checked CheckBox in JTree only when user click on CheckBox?" New topic
Author

How to mark checked CheckBox in JTree only when user click on CheckBox?

Premal Panchal
Greenhorn

Joined: May 09, 2005
Posts: 6
Hi,

In my application I am showing JCheckBox with every node of JTree. My requirement is JCheckBox should be selected or deselected only when user click on JCheckBox not by clicking on the Node. Means if I click the text part of node it should not select or deselect the JCheckBox. I have seen various sites like CodeGuru etc. for getting JCheckBox with JTree, but they have not provided the solution of my problem. So is ther any way to achieve what I want? Any suggestion regarding this will be appreciated.

Thanx and Regards,

Premal Panchal
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

I'm not sure that is possible. I believe that when the JTree renders the JCheckBox it is not really rendering that actual component but a visual representation of that JCheckBox. The JTree handles check box selection by listening for which "node" you select and propigating an action down to the actual component that is being rendered.


GenRocket - Experts at Building Test Data
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Sure it is. What you have to do is ignore tree selection events and listen for mouse clicks. Determine with each mouse click whether or not it was over a check box. I'll have to dig into the API a little bit if you want a specific example but it's certainly possible as I did just that in a project about a year ago.
Premal Panchal
Greenhorn

Joined: May 09, 2005
Posts: 6
Hi Gregg,

I have already tried, but when i got the point where mouse is clicked at that time i couldnt find check box at that.. i tried other ways also..if possible then try at ur convenience and try to give me sample code...

Thanx in advance,

Premal Panchal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to mark checked CheckBox in JTree only when user click on CheckBox?