node of Jtree..how to disable it
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: node of Jtree..how to disable it

  1. #1
    Join Date
    Sep 2001
    Location
    Bangalore
    Posts
    98

    node of Jtree..how to disable it

    Hi,
    I have a Jtree and I want to prevent user selecting some nodes of this tree.I did this by adding a TreeSelectionListner to the tree and then in the value changed method of this listner ,I checked the current node is the node that I dont want user to select,I used the method removeSelectionPath(TreePath tp).


    In my approach what i am doing is first allowing the user to select the node and then removing the selection from node.
    Is there any method to prevent the user from selcting a node at the inital state only by using the TreeSelectionModel.

    Help is needed
    A

  2. #2
    Join Date
    Mar 2003
    Location
    Lincoln, Nebraska
    Posts
    134
    Interesting problem. Creating a custom TreeSelectionModel would likely work. Without spending some time examining the interface I can't say what you would have to override though.

    Another thought did occur to me: is it imperitive that the node not be selected, or that it just doesn't SHOW selection? If you simply need it to not be highlighted when a user clicks on it, then you could override the getTreeCellRendererComponent() method of the DefaultTreeCellRenderer. In that method, the DefaultTreeCellRenderer checks to see if a cell is selected and changes the foreground and background. All you would have to do is do whatever you need to determine if the node should show selection and change this behavior. The rest of the method could be copied as is, I would think.

    Note, this is just an idea. I have obviously not tried this. Maybe Viravan has a better suggestion.

  3. #3
    Join Date
    Sep 2001
    Location
    Bangalore
    Posts
    98
    Originally posted by Nemi


    Another thought did occur to me: is it imperitive that the node not be selected, or that it just doesn't SHOW selection? If you simply need it to not be highlighted when a user clicks on it, then you could override the getTreeCellRendererComponent() method of the DefaultTreeCellRenderer. In that method, the DefaultTreeCellRenderer checks to see if a cell is selected and changes the foreground and background. All you would have to do is do whatever you need to determine if the node should show selection and change this behavior. The rest of the method could be copied as is, I would think.
    I have tried that and in the getTreeCellRendererComponent method i have disabled the node which i want not to be selected.
    But unfortunately I dont have to use this method and I am supposed to use TreeSelection Model.
    Thnakx for the idea....but ????

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center