Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-24-2008, 10:31 AM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
Rep Power: 0
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
Question How to disabled a node.
Hi All,

I am trying to disabled one node using following code:

child = new DefaultMutableTreeNode("Inventory");
parent.add(child);

child.setEnabled(false);

but when i am compiling it i am getting the following error:

Navigate1.java:348: cannot find symbol
symbol : method setEnabled(boolean)
location: class javax.swing.tree.DefaultMutableTreeNode
child.setEnabled(false);


Please Help...

Thanks in advance...:

Last edited by smartsubroto; 06-24-2008 at 10:49 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 06-24-2008, 11:29 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Can you show your code. Hard to tell anything looking at the code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-25-2008, 08:52 AM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
Rep Power: 0
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
Default
child = new DefaultMutableTreeNode("Inventory");
parent.add(child);

child.setEnabled(false);

model = new DefaultTreeModel(parent);
tree = new JTree(model);
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
linksRenderer = new DefaultTreeCellRenderer();
linksRenderer.setBackgroundNonSelectionColor(Color .lightGray);
linksRenderer.setBackgroundSelectionColor(Color.WH ITE);
tree.setCellRenderer(linksRenderer);
JScrollPane treeView = new JScrollPane(tree);
treeView.setPreferredSize(new Dimension(250, 350));

panel.add(treeView);
treeView.setBounds(10,40,300,430);
tree.setBackground(Color.lightGray);


in the above code

"Parent" is the root node and the "Child" is leaf of that node in a JTree.

and i want to disable the leaf node..

Plz suggest something
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-25-2008, 09:00 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
I think you can try something like this. On a click of the leaf get the leaf name. Compare it with the name of the leaf you want to disable. If it's true make setEnable(false)

You have try something like this at the start of code.

Code:
child.setEnabled(false);
What happened there, did you debug and see it?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-25-2008, 10:44 AM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 307
Rep Power: 2
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Default
Generally we get "cannot find symbol" error to such java classes when the imports for it are not present, please do check that once.

Or another probable reason would be because u r making it disabled before adding it to the tree. Try first adding it to the mutabletree and then making it disabled at the end.(i am not sure of it, its just my guess)
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-25-2008, 11:14 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Yep, that's why I'm worried about the mentioned line of code. Just after declaring set to disable.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-25-2008, 11:55 AM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 307
Rep Power: 2
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Default
Hi,
Can u(person who initiated this thread) post the whole code from end to end instead of a part of it.

Before thay try the given suggestion,that may solve ur problem
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-25-2008, 11:58 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
That's the best thing if you grab the correct issue from the code. In shorter period you can have the solution.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-25-2008, 12:43 PM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
Rep Power: 0
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
Default
i use the following code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.ImageIcon;
import java.net.URL;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

public class TreeDemo
{
JFrame f1;
JPanel p1;
static JTree tree;
DefaultTreeModel model;
DefaultTreeCellRenderer linksRenderer;
DefaultMutableTreeNode parent,child1,child2;
public TreeDemo()
{
f1=new JFrame("Tree Demo");
p1=new JPanel();
f1.getContentPane().add(p1);

parent = new DefaultMutableTreeNode("Parent");

child1 = new DefaultMutableTreeNode("Child1");
parent.add(child1);

child2 = new DefaultMutableTreeNode("Child2");
parent.add(child2);

child2.setEnabled(false);

model = new DefaultTreeModel(parent);
tree = new JTree(model);
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
linksRenderer = new DefaultTreeCellRenderer();
linksRenderer.setBackgroundNonSelectionColor(Color .lightGray);
linksRenderer.setBackgroundSelectionColor(Color.WH ITE);
tree.setCellRenderer(linksRenderer);
JScrollPane treeView = new JScrollPane(tree);
treeView.setPreferredSize(new Dimension(250, 350));

p1.add(treeView);
treeView.setBounds(10,40,300,430);
tree.setBackground(Color.lightGray);

f1.setSize(400,400);
f1.show();
}
public static void main(String args[])
{
new TreeDemo();
}
}


and the error..

D:>javac treedemo.java
treedemo.java:43: cannot find symbol
symbol : method setEnabled(boolean)
location: class javax.swing.tree.DefaultMutableTreeNode
child2.setEnabled(false);
^
Note: treedemo.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error


Plz... Suggest..
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 06-25-2008, 01:20 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Do you want to block all childes of a leaf, right?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 06-25-2008, 01:33 PM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
Rep Power: 0
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
Default
No i just want to block one child leaf.

and also if we can block any one child then there will no problem in blocking of whole node..
__________________
Thanks & Regards
Subroto Bhattacharjee
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 06-25-2008, 01:34 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
So why don't you try to set setAllowsChildren() false on the specific child node.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 06-25-2008, 02:06 PM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
Rep Power: 0
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
Default
setAllowsChildren(boolean) is used to set, wheather the node is able to have children or not.

This command is not disabling the leaf..

I use this code as:

child2.setAllowsChildren(false);

but it does nothing in this case..
__________________
Thanks & Regards
Subroto Bhattacharjee
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 06-25-2008, 03:26 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 307
Rep Power: 2
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Default
Hi,
Check this link, it has something similar like what u want.

How to disable a certain treenode in a jtree (Swing / AWT / SWT / JFace forum at JavaRanch)
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 06-26-2008, 04:27 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Originally Posted by smartsubroto View Post
setAllowsChildren(boolean) is used to set, wheather the node is able to have children or not.

This command is not disabling the leaf..

I use this code as:

child2.setAllowsChildren(false);

but it does nothing in this case..
If I got you correctly this is what you want to do, right?

Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.tree.*;

public class TreeDemo {

    JFrame f1;
    JPanel p1;
    static JTree tree;
    DefaultTreeModel model;
    DefaultTreeCellRenderer linksRenderer;
    DefaultMutableTreeNode parent,child1,child2, child3;

    public TreeDemo() {
        f1 = new JFrame("Tree Demo");
        p1 = new JPanel();
        f1.getContentPane().add(p1);

        parent = new DefaultMutableTreeNode("Parent");
        child1 = new DefaultMutableTreeNode("Child1");
        parent.add(child1);

        child2 = new DefaultMutableTreeNode("Child2");
        parent.add(child2);

        child3 = new DefaultMutableTreeNode("child3");
        child2.add(child3);

        model = new DefaultTreeModel(parent);
        tree = new JTree(model);
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
        linksRenderer = new DefaultTreeCellRenderer();
        linksRenderer.setBackgroundNonSelectionColor(Color .lightGray);
        //linksRenderer.setBackgroundSelectionColor(Color.WH ITE);
        tree.setCellRenderer(linksRenderer);
        JScrollPane treeView = new JScrollPane(tree);
        treeView.setPreferredSize(new Dimension(250, 350));

        child2.setAllowsChildren(false); // Try changing the status 
        
        p1.add(treeView);
        treeView.setBounds(10,40,300,430);
        tree.setBackground(Color.lightGray);

        f1.setSize(400,400);
        f1.show();
    }

    public static void main(String args[]) {
        new TreeDemo();
    }
}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 06-26-2008, 07:21 AM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
Rep Power: 0
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
Default
here
chil2.setAllowsChildren(false);

is not useful to disable a leaf.
__________________
Thanks & Regards
Subroto Bhattacharjee
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 06-26-2008, 07:27 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
That mean I'm still not get what you exactly wants.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 06-26-2008, 11:50 AM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
Rep Power: 0
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
Default
I just want to disable that particular leaf.

for EX:
if there is buttton say..
JButton b1=new JButton("I Am Disable");
b1.setEnabled(false);

in the above case button is there but it is disabled.
I just want to implement the same thing in leaf.
__________________
Thanks & Regards
Subroto Bhattacharjee
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 06-26-2008, 12:32 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 307
Rep Power: 2
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Default
Hi,
did u check the link i provided before?
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 06-26-2008, 12:44 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,464
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Originally Posted by smartsubroto View Post
I just want to disable that particular leaf.

for EX:
if there is buttton say..
JButton b1=new JButton("I Am Disable");
b1.setEnabled(false);

in the above case button is there but it is disabled.
I just want to implement the same thing in leaf.
Ok, in that sense disable a leaf is, it's there and you can't workout with it's child, isn't it?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Node selection in jtree Preethi AWT / Swing 4 06-20-2008 12:25 AM
Drag and drop of multiple elements of a node in a Tree Avdhut AWT / Swing 2 06-03-2008 10:07 PM
how to create Popup Menu with Sub Menu while right-clicking the JTree Node?? Kabiraa AWT / Swing 7 05-09-2008 08:54 AM
JTree Programmatic Node Expansion and Selection Probelm hemanthjava AWT / Swing 1 01-17-2008 07:36 AM
How to Transmit data from one node to another swimberl Networking 2 01-04-2008 09:48 PM


All times are GMT +2. The time now is 07:07 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org