Results 1 to 6 of 6

Thread: jtree's in netbeans 4.1

  1. #1
    Senior Member
    Join Date
    May 2005
    Posts
    434
    Thanks
    0
    Thanked
    0 times in 0 posts

    jtree's in netbeans 4.1

    Hi i have made a jtree in netbeans and i made this code in the pre creation code for the jree:

    Code:
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Users");
                DefaultMutableTreeNode online = new DefaultMutableTreeNode("Online");
                root.add(online);
                DefaultMutableTreeNode offline = new DefaultMutableTreeNode("Offline");
                root.add(offline);
    The problem is that the jtree still displays the default node values i,e (colours, sports, foods). I know that their is no way in chaninging these nodes in design view and that the only way is to code it in the properties of the jtree. i did that and nothing happens to the jtree at all...

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    What do you mean the JTree displays it's "default" node values? Is this a netbeans thing? Can we see the rest of the code?

    Looking through the DefaultMutableTreeNode class it seems you are trying to initialise with the Constructor "DefaultMutableTreeNode(Object userObject) ". If the colour, sports and food nodes you are refering to are indeed of type DefaultMutableTreeNode then I assume you can change their title with the method "nodeInstance.setUserObject("StringValue")"

    Never used it before so I'm just taking educated guesses from the Java javadoc api : http://java.sun.com/j2se/1.5.0/docs/api/index.html

    And if I can guess just by looking at the API, someone with a full-featured JAVA IDE that I assume uses reflection, who's working on the code, with the API's available should be able to figure it out
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Commander Keen
    Join Date
    Nov 2003
    Location
    217.27.240.214
    Posts
    624
    Thanks
    0
    Thanked
    0 times in 0 posts
    I think he means that the "design view" of the GUI renders a few default values like a heirarchy of some sort e.g. colours, dogs, fish etc

    But when you actually run the application it has these default values and not the values he wants them to be i.e. "online" or "offline" by the looks of it.

    Try:

    JTree.update()

    I did program something with JTrees in net beans a few weeks back and know what your on about but dont have the code to hand at the moment. I think it is update that forces the GUI to use your new data. Hope that helps
    Last edited by killgORE; 14-05-2006 at 11:12 PM.

  4. #4
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Well if that is the case there must be underlying code that instantiates these trees, why not just remove that code.
    To err is human. To really foul things up ... you need a computer.

  5. #5
    Commander Keen
    Join Date
    Nov 2003
    Location
    217.27.240.214
    Posts
    624
    Thanks
    0
    Thanked
    0 times in 0 posts
    Its unfortunately in the code block that net beans does not like you to touch, I also couldn't see it when I looked. Regardless if you have a similar GUI to me and lets face it it is no doubt from the same template.. Involves a JTree so yep.

    In your constructor underneath init <-- where the IDE doesn't want you to touch it.

    Code:
            
    initComponents() ;
    root_node =new DefaultMutableTreeNode("Nothing");
    DefaultTreeModel treeModel = new DefaultTreeModel(root_node);
    DataTree.setModel(treeModel) ;
    Then something to explicitly set it to nothing for convenience a method like "setupTree" will need something like this:

    Code:
    root_node = null ;
    root_node = new DefaultMutableTreeNode(host);
    DefaultTreeModel treeModel = new DefaultTreeModel(root_node);
    DataTree.setModel(treeModel) ;
    I am thinking now that it is this wonderful setModel() function thats doing the GUI updating for me. Filthy hacked together code but its doing what I needed it to.

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked
    0 times in 0 posts

    Getting rid of the default JTree values

    After doing this in the Pre-creation code you also have to add the line "=new JTree(root);" in the custom creation code of the designer.

    Hope this helps.


    Quote Originally Posted by jonneymendoza View Post
    Hi i have made a jtree in netbeans and i made this code in the pre creation code for the jree:

    Code:
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Users");
                DefaultMutableTreeNode online = new DefaultMutableTreeNode("Online");
                root.add(online);
                DefaultMutableTreeNode offline = new DefaultMutableTreeNode("Offline");
                root.add(offline);
    The problem is that the jtree still displays the default node values i,e (colours, sports, foods). I know that their is no way in chaninging these nodes in design view and that the only way is to code it in the properties of the jtree. i did that and nothing happens to the jtree at all...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 22-12-2005, 01:41 AM
  2. Netbeans 4.1
    By Kezzer in forum Software
    Replies: 11
    Last Post: 08-06-2005, 12:11 PM
  3. Netbeans 4.1 RC and Profiler...
    By suryad in forum Software
    Replies: 3
    Last Post: 23-04-2005, 11:20 AM
  4. netbeans and changing source dir
    By Kezzer in forum Software
    Replies: 3
    Last Post: 12-04-2005, 07:14 PM
  5. NetBeans won't let me use UserInput ...
    By unrealrocks in forum Software
    Replies: 1
    Last Post: 09-03-2004, 09:31 PM

Posting Permissions

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