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.
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.
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.
Joined: May 09, 2005
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,
subject: How to mark checked CheckBox in JTree only when user click on CheckBox?