How to disable a particular node in JTree?

Hi
I am working with an application where in which I have a tree component and when a select a node and click a disable button , I want to disable the selected node(that is no further selection of that node possible until I enable it). I am using DefaultTreeCellRenderer for rendering nodes. I tried the following.
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer)tree.getCellRenderer();
JLabel label = (JLabel) renderer.getTreeCellRendererComponent(tree,selectedNode,true,true,false,row,true);
label.setEnabled(false);
But it doesn't work.
Does any one know how to do this?
Thank you.

Its not going to work if you implement the TreeCEllRenderer, cos' all it does is paint your tree.
What u need to implement is the treeSelectionListener interface,
and override the addSelectedPath(path), addSelectedPath(paths[]) etc.
You might want to create a list of all the nodes that the user selectes to diable, and then in these methods decide if the node is that then do not allow its selection.

Similar Messages

  • How to reach at a node of JTree : Urgent

    Hay all,
    Plz tell me that how to reach at a particular node in a JTree, whose name is known to you.I have used a DefaultTreeModel to create a tree. As
    deviceTreeModel=new DefaultTreeModel(rootNode);
    tree = new JTree( deviceTreeModel );
    Thanks and Regards,
    Sharad Agarwal

    an inefficient way is to traverse the tree to find the node
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
    public TreeNode getNode(DefaultMutuableTreeNode node, String nodeName){
        if (node.getChildCount() == )
            return null;
         for (Enumeration e = node.childrens() ; e.hasMoreElements() ;) {
             DefaultMutuableTreeNode child = (DefaultMutuanbleTreeNode) e.nextElement();
             if (child.getUserObject.().toString().equals(nodename))
                 return child;
             else
                 getNode(child, nodeName);
    }once you got the node, you can use the
    DefaultTreeModel.insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)

  • How to disable a particular cell in JTable ?

    I having a problem on how to set disable a particular cell in JTable. At the first place to load the JTable, I want to set some of the cell to disabled, it only will run at the first time, is there anyway to do it ?

    This is the function that disable/enable cells in JTables.
    Are you looking for this?
    public boolean isCellEditable(int row, int col)
      if(((new Integer((String)(getValueAt(row,0)).toString()).intValue()>9))&&(col==1))
        return true;
      if(row!=4&&col!=5)
        return true;
      return false;
         this metod belong to the TableModel function
    and what I gave you is only an example of what you can do with it.
    if it return false it disable and if true it enable the cell...but I think this you allready know!
    Regards Amnon

  • How to search in particular node

    hi
    kindly tell how can we limit our search to a particular node instaed of the whole content
    thanks in advance

    Since it's all text, why not use a real quick Match Pattern (or Regular Expression, but you don't need that much power here), see attached.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ
    Attachments:
    Two-stage match demo.vi ‏8 KB

  • How to disable a particular CELL in matrix?????

    Hi All,
               I have a doubt regarding the matrix.In my matrix the first column is a combobox it has a,b,c items....so if i select 'a' the remaining 'b' & 'c' columns should get disabled....previously iam able to disable the 'b' & 'c' columns but it's disabling the total 'b & 'c' columns in my matrix.....i just want to disable the particular cell based on the combobox selection....can we disable a particular cell in matrix.....
    regards,
    shangai.

    Shangai,
    here were many threads about this in last month. Try to search in history.
    BTW, the particular cell cannot be disabled (only whole column), but you could make system, that the cell is enabled but you cannot click on it (when user clicks on the cell, set bubbleeevnt to fasle).

  • How to rename a particular node in an xml

    Hi All,
    I have a table called xmltable and I have inserted the below row in to the table,
    INSERT INTO XMLTABLE VALUES (4,'<?xml version="1.0"?>
    <Node_1 empID="202" empName="Pro1" oper="Update">
    <Node_2 empID="20" empName="Pro2" oper="Update">
    <Node_3 empID="2" empName="Pro3" oper="Update">
    <Node_4 empID="22" empName="Pro4" oper="Update">
    <Node_5 empID="12" empName="Pro5" oper="Delete"/>
    <Node_6 empID="223" empName="Pro6" oper="Insert"/>
    <Node_7 empID="201" empName="Pro7" oper="All"/>
    </Node_4>
    </Node_3>
    </Node_2>
    </Node_1>');
    I Have created a sequence seq_i
    I want to replace a particular node with next sequence seq_i,
    Ex: - Assume I want to replace only 'Node_2' with 'seq_i.nextval',
    Can any one help me in acheiving this?
    Thanks,

    Sorry for the inconvenience, Below Find detailed explanation of the issue,
    INSERT INTO XMLTABLE VALUES (4,'<?xml version="1.0"?>
    <Node_1 empID="202" empName="Pro1" oper="Update">
    <Node_2 empID="20" empName="Pro2" oper="Update">
    <Bode_3 empID="2" empName="Pro3" oper="Update">
    <Bode_4 empID="22" empName="Pro4" oper="Update">
    <Bode_5 empID="12" empName="Pro5" oper="Delete"/>
    <Bode_6 empID="223" empName="Pro6" oper="Insert"/>
    <Bode_7 empID="201" empName="Pro7" oper="All"/>
    <Node_3 empID="21" empName="Pro71" oper="ll">
    </Bode_4>
    </Bode_3>
    </Node_2>
    </Node_1>');
    I have a sequence seq_i
    seq_i start with 1 increment by 1
    am able to display output as below,
    Node|EMPID|OPER|EMPNAME|MGRID
    Node_1|202|Update|Pro1|Null
    Node_2|20|Update|Pro2|Node_1
    Bode_3|2|Update|Pro3|Node_2
    Bode_4|22|Update|Pro4|Bode_3
    Bode_5|12|Delete|Pro5|Bode_4
    Bode_6|223|Insert|Pro6|Bode_4
    Bode_7|201|All|Pro7|Bode_4
    Node_3|21|ll|Pro71|Bode_4
    Now I want below one as output
    All nodes starting with Bode_, I need to replace that with sequence, seq_i
    so for the seq_i (starting with i and incrementing by 1)
    Node|EMPID|OPER|EMPNAME|MGRID
    Node_1|202|Update|Pro1|Null
    Node_2|20|Update|Pro2|Node_1
    1|2|Update|Pro3|Node_2
    2|22|Update|Pro4|1
    3|12|Delete|Pro5|2
    4|223|Insert|Pro6|2
    5|201|All|Pro7|2
    Node_3|21|ll|Pro71|2
    Thanks,

  • How to set a particular node selected in a JTree from within the model

    I have an adapter class that provides communication between my JTree and data model. My adapter class implements TreeModel, TreeExpansionListener, TreeSelectionListener and a listener for changes to my data model.
    My data model keeps reference to the currently selected node. It is working quite nicely when I select a tree node with the mouse (the data model is updated accordingly with the node selected), however my problem occurs trying to go the other way (set the selected node in my data model and have it reflected in the tree).
    I know that my selection in the tree is changing correctly as when the selection changes it fires off an event to update the attributes window associated with the currently selected node. I just can't get the node to become highlighted.
    Any ideas would be most welcome.
    Thanks,
    Beck.

    Does your model really have to keep track of the selected item or can the two views (the JTree and the attributes window) not be coupled together in the user interface instead?
    Failing that, you could always consider implementing TreeSelectionModel as well and calling JTree.setSelectionModel since you're keeping track of the tree selection for it already. This is quite a bit of work though.
    If that's too much trouble then if you can work out the TreePath for the node that's been programmatically selected through your model then you could use JTree.getSelectionModel().setSelectionPath. Have a look at tree.getSelectionModel().setSelectedPath(new TreePath(selectedObject)).
    This approach is a bit warped, though, since it implies that your model knows about the view and therefore couples them together.

  • How to disable a particular row in a JTable

    How can a disable only a particular row/column in a JTable.
    I am trying to create an XML Notepad type of application for which I need the row which contains the root element or any element which has a child element to be disabled. How can I achieve this??
    I would be grateful for replies.

    Hi,
    Create your own class which extends TableModel and in that class u override the method
    public boolean isCellEditable( int row, int col)
    As u know the row and col which u want to disable hard code those values in the method.
    Like
    public boolean isCellEditable( int row, int col)
    if( row == 2 and col == 1 )
    return false
    else
    return true
    Hopefully this provides u with a solution.
    Cheers :)
    Nagaraj

  • How to search a child node in JTree

    Hi I am new to swings..
    My requirement is I have a Jsplit pane.
    I have search button with a text box in one and Jree in another pane.
    When I enter a string and hit Search button...It need to search the tree and expand that node highlight it.
    can anyone help in getting this done.

    public void actionPerformed(ActionEvent e)
      DefaultTreeModel m_model = new DefaultTreeModel(entityRoot);
      DefaultMutableTreeNode node = searchNode(m_searchText.getText());
      JTree m_tree = new JTree(m_model);
      TreePath root = m_tree.getPathForRow(0);
      searchTree(m_tree, root, m_searchText.getText());
    private void searchTree(JTree tree, TreePath path, String q)
    TreeNode node = (TreeNode)path.getLastPathComponent();
    if(node==null) return;
    if(node.toString().startsWith(q))
       tree.setScrollsOnExpand(true);
       tree.setSelectionPath(path);
    if(!node.isLeaf() && node.getChildCount()>=0)
       Enumeration e = node.children();
       while(e.hasMoreElements())
       searchTree(tree, path.pathByAddingChild(e.nextElement()), q);
    }Edited by: EJP on 27/06/2011 09:53: added {noformat}{noformat} tags. Please use them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Setting the color of a particular node in JTree

    Hi all!
    I'm new to Java and facing a problem with JTrees.
    I'm using the following snippet to create a JTree :
    DeafultMutableTreeNode root = new DefaultMutableTeeNode("Letters");
    DeafultMutableTreeNode parent1 = new DefaultMutableTeeNode("uppercase");
    DeafultMutableTreeNode parent2 = new DefaultMutableTeeNode("lowercase");
    DeafultMutableTreeNode child1 = new DefaultMutableTeeNode("A");
    DeafultMutableTreeNode child2 = new DefaultMutableTeeNode("B");
    DeafultMutableTreeNode child3 = new DefaultMutableTeeNode("C");
    DeafultMutableTreeNode child4 = new DefaultMutableTeeNode("a");
    DeafultMutableTreeNode child5 = new DefaultMutableTeeNode("b");
    DeafultMutableTreeNode child6 = new DefaultMutableTeeNode("c");
    root.add(parent1);
    root.add(parent2);
    parent1.add(child1);
    parent1.add(child2);
    parent1.add(child3);
    parent2.add(child4);
    parent2.add(child5);
    parent2.add(child6);
    JTree tree = new JTree(root);
    JScrollPane pane = new JScrollPane(tree);
    TreePath path = tree.getNextMatch("lowercase", 0, javax.swing.text.Position.Bias.Forward);
    tree.setSelectionPath(path);
    tree.expandPath(path);
    In the above JTree, the node labeled "lowercase" gets selected and expanded as soon as the program is run.
    What i want to know is that, is there any way in which i can set only the "lowercase" node's background to a different color (say, YELLOW) and have it so, no matter if the node is expanded or collapsed or other nodes are expanded or collapsed.
    ps: Sample snippet would really b helpful.

    You need to write your own renderer for this.
    Read the tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display

  • How to select a particular node in a tree?-want suggestions urgent

    i've to make a tree showing "c:\" folder structure of the system. Initially i'm adding the folders in c:\ only tothe tree. And i'm adding the subfolders when ever i select a particular folder. I'm opening the subfolders and inner subfolders of it and so inside like that. now i'm closing the window . i want the tree to reopen with the previously opened level when ever i again run the program. On closing i'm storing the last selected node using tree.getMaxSelectionPath() . And on reopen i'm setting it as tree.setSelectionPath(tree.getMaxSelectionPath()).
    But it is not opening the entire path. it is opening uptop one level only. what to do. Needs suggestion urgently.
    Thnaks for suggestons.

    Hi again,
    I am sorry, I cannot help in another way than looking at the documentation, because I have currently no JDK available here. If expandPath(...) doesn't work, you can try to get all the nodes of that path and expand them from the root node downwards, perhaps that will work.
    greetings Marsian

  • How to disable a particular list item in flash cs3

    Friends,
    I need a small help on list component in flash cs3.
    assume that i have 5 items in my list and i want to disable 3,4,5 items from mylist box. how to do this ??
    item 1 -- enabled state
    item 2 -- enabled state
    item 3 -- disabled state
    item 4 -- disabled state
    item 5 -- disabled state
    using flash cs3, i want to achieve this , how to do this ?? any ideas pls..
    Rajesh

    Hi Rajesh,
    I've seen your query all over the internet, so I should warn you I don't believe it's possible to disable a List Item.
    For that you should use Josh Tynjala's open source Advanced List (http://code.google.com/p/flextoolbox/downloads/list).
    Best Regards,
    Filipe.

  • How can I remove child node from JTree???

    Hi,
    I would like to remove all the child node of my jtree. For instance I would like to remove the c, d, and e nodes. It's possible to remove all the child node or to remove by her name ("c", "d", and "e"). If yes what is the method that it permit to do.
    A-----
    |
    b-------c
    |
    |--------d
    |
    ---------e
    I use the model : DefaultMutableTreeNode
    Thanks

    There are a couple of ways it can be done. If your tree uses DefaultTreeModel as its TreeModel, you can use removeNodeFromParent(). This will remove the node from its parent and effectively remove its children, too. All nodes removed will be garbage-collected if there are no other references to them.
    If your tree model is not the default tree model, but still uses MutableTreeNode, you can use either remove() or removeFromParent() on the node itself, depending on whether you want to remove the node itself or one of its children.
    On the other hand, your tree may use a model that simply "mirrors" another data structure, in which case you would have to remove the node from the other data structure and have it reflected in the model.

  • How to Disable a PARTICULAR action key?

    Hi,
    I know how to turn off action keys from BIOS. What i want to is just disable the help action of the F1key. I basically want it o have no fuction (so that it would perform the assigned function for the game) like the f5 key on my Envy 15t. I use the f1 key in games, since every time i press it it opens up the help, i want to disable it. However, i do not want to disable the rest and want to be able use them without having to press the FN key. 
    I am not sure if there is a solution to this problem but i would still love to hear some suggestions.
    Thank You.

    Hi,
    If just for Windows XP: you should be able to disable the help stuff by disabling the Help and Support service. (start->type services.msc->press enter).
    And for Windows 7 (Vista could be the same):
       http://www.sevenforums.com/customization/171360-there-way-totally-disabling-f1-hotkey.html
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How to skip a particular node in a script using test manager

    Hi,
    We are testing a script recorded for custom forms in R12 on two different instances using test manager.For one instance its running fine.
    But in the second instance one message note is not coming (one note which was present during recording is not there after the instance was refreshed). During Playback that node is not matching with recorded script so "object not found error is coming".Is there any way we can bypass that recording during playback through test manager ? Any kind of help is appreciated.
    Regards,
    Vishal

    Sorry for the inconvenience, Below Find detailed explanation of the issue,
    INSERT INTO XMLTABLE VALUES (4,'<?xml version="1.0"?>
    <Node_1 empID="202" empName="Pro1" oper="Update">
    <Node_2 empID="20" empName="Pro2" oper="Update">
    <Bode_3 empID="2" empName="Pro3" oper="Update">
    <Bode_4 empID="22" empName="Pro4" oper="Update">
    <Bode_5 empID="12" empName="Pro5" oper="Delete"/>
    <Bode_6 empID="223" empName="Pro6" oper="Insert"/>
    <Bode_7 empID="201" empName="Pro7" oper="All"/>
    <Node_3 empID="21" empName="Pro71" oper="ll">
    </Bode_4>
    </Bode_3>
    </Node_2>
    </Node_1>');
    I have a sequence seq_i
    seq_i start with 1 increment by 1
    am able to display output as below,
    Node|EMPID|OPER|EMPNAME|MGRID
    Node_1|202|Update|Pro1|Null
    Node_2|20|Update|Pro2|Node_1
    Bode_3|2|Update|Pro3|Node_2
    Bode_4|22|Update|Pro4|Bode_3
    Bode_5|12|Delete|Pro5|Bode_4
    Bode_6|223|Insert|Pro6|Bode_4
    Bode_7|201|All|Pro7|Bode_4
    Node_3|21|ll|Pro71|Bode_4
    Now I want below one as output
    All nodes starting with Bode_, I need to replace that with sequence, seq_i
    so for the seq_i (starting with i and incrementing by 1)
    Node|EMPID|OPER|EMPNAME|MGRID
    Node_1|202|Update|Pro1|Null
    Node_2|20|Update|Pro2|Node_1
    1|2|Update|Pro3|Node_2
    2|22|Update|Pro4|1
    3|12|Delete|Pro5|2
    4|223|Insert|Pro6|2
    5|201|All|Pro7|2
    Node_3|21|ll|Pro71|2
    Thanks,

Maybe you are looking for

  • BPM handle empty message in send step

    Hi, Friends: I have a following BPM sceario(PI7.1 EHP1) It mainly has following steps: Receive -> Transformation (Multi-Mapping) -> Fork (4 branches: one send step each branch) The multi-mapping result is to generate 4 types of messages based on logi

  • How to move my entire music library to another drive?

    i bought a new faster, bigger drive and would like to move all the itunes stuff to that new hard drive Can i do it? How? Thank's

  • APP-SQLAP-10710: Online Accounting could not be created

    Hi, The following error occurs when trying to run the "Create Accounting" procedure for an invoice: "APP-SQLAP-10710: Online Accounting could not be created. Please submit the Payables Accounting Process instead to create accounting entries for this

  • Database Level Tracing or Instance Level Tracing

    Hello, How do I know whether database level tracing or instance level tracing is enabled ? This is on 10g R2 Thanks, R

  • Backing up to external!? help!

    i have a 250GB external HD and i want to backup my settings, apps and pictures, movies, documents etc. So is there like a step by step or program that is easy to use. im pretty knowledgable when it comes to macs i just cant seem to grasp this externa