Disable checkbox in a CheckBoxTree

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Disable checkbox in a CheckBoxTree

Postby hbrtest » Mon Jan 24, 2011 7:17 am

Hi Jidesoft,
I looked at the demo code, javadoc and at this forum but can't figure out how to disable a checkbox on a CheckBoxTree.
I created a CheckBoxTree and have the following DefaultTreeCellRenderer on it. I set the renderer using the method on CheckBoxTree. Most works as expected but the checkbox is NOT enabled. How do achieve that?

Thanks, Werner.

Code: Select all
public class ImageLayerTypesListTreeCellRenderer extends DefaultTreeCellRenderer {

    private static final String MAP_LEGEND_IMAGE_PATH = "../maplegend/icon.%s.png";

    public Component getTreeCellRendererComponent(final JTree tree, final Object node, final boolean sel,
            final boolean expanded, final boolean isLeaf, final int row, final boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, node, sel, expanded, isLeaf, row, hasFocus);
       
        if (isLeaf && ((DefaultMutableTreeNode) node).getUserObject() instanceof ImageLayerTypeModel) {
            ImageLayerTypeModel model = (ImageLayerTypeModel) ((DefaultMutableTreeNode) node).getUserObject();
           
            final ImageIcon image = ImageUtilities.loadImageIcon(String.format(MAP_LEGEND_IMAGE_PATH,
                                                                                                                  model.getImageLayerType().name()), false);
            setIcon(image);
            setText(model.getImageLayerType().getFullName());
            if(!model.isEnabled()) {
               setEnabled(false);
               setForeground(Color.gray);
            }
        }
        return this;
    }
}
hbrtest
 
Posts: 53
Joined: Mon Aug 10, 2009 1:14 am

Re: Disable checkbox in a CheckBoxTree

Postby JIDE Support » Mon Jan 24, 2011 11:48 am

Please override CheckBoxTree#isCheckBoxEnabled(TreePath) to disable the specific node.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Disable checkbox in a CheckBoxTree

Postby hbrtest » Tue Jan 25, 2011 3:22 am

Thanks!
The checkboxes now appear disabled when I want them to. However, I also when setDigIn = false I am able to select a node.
Is that a bug? Please note that I use version 2.8.2.
hbrtest
 
Posts: 53
Joined: Mon Aug 10, 2009 1:14 am

Re: Disable checkbox in a CheckBoxTree

Postby JIDE Support » Tue Jan 25, 2011 12:08 pm

Can you please elaborate your issue again? I don't think setDigIn(false) would block the customer to select a node. A test case would be highly appreciated.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 77 guests