Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-24-2008, 11:31 AM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
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 11:49 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-24-2008, 12:29 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Can you show your code. Hard to tell anything looking at the code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-25-2008, 09:52 AM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
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, 10:00 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-25-2008, 11:44 AM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
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, 12:14 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-25-2008, 12:55 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
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, 12:58 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-25-2008, 01:43 PM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
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, 02:20 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Do you want to block all childes of a leaf, right?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 06-25-2008, 02:33 PM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
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
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 06-25-2008, 02:34 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
So why don't you try to set setAllowsChildren() false on the specific child node.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 06-25-2008, 03:06 PM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
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
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 06-25-2008, 04:26 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
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, 05:27 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
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.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 06-26-2008, 08:21 AM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
here
chil2.setAllowsChildren(false);

is not useful to disable a leaf.
__________________
Thanks & Regards
Subroto Bhattacharjee
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 06-26-2008, 08:27 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
That mean I'm still not get what you exactly wants.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 06-26-2008, 12:50 PM
smartsubroto's Avatar
Member
 
Join Date: May 2008
Location: India,Kolkatta
Posts: 50
smartsubroto is on a distinguished road
Send a message via Yahoo to smartsubroto
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
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 06-26-2008, 01:32 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
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, 01:44 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura about