Tree with checkbox nodes and radiobutton subnodes.!

Posted on 2005-05-04
Last Modified: 2012-08-13
Hi all,
Working on JBuilder X, java 1.4, My application requires a  tree structure that needs to be displayed of following format:
Eatry (1. Main root)
      (1.1 checkbox)Fruits
            (1.1.1 radiobutton) orange
            (1.1.2 radiobutton) banana
            (1.1.3 radiobutton) apple
      (1.2 checkbox)Vegetable
            (1.2.1 radiobutton) spinach
            (1.2.2 radiobutton) potato
            (1.2.3 radiobutton) onion
i.e user has option to select any or both "Fruits" and "Vegetable", but is given option to select only one of the fruit /vegetable

item at a time. So checkbox across the 1.1 and 1.2 and radiobutton for the type of fruits or vegetable.
I need to build this tree structure inside a dialog which is further placed in the panel.
My query is as follows:
1) Do I need to make my own Tree completely extending JTree  and CTreeRenderer ofcourse. ? Or JAVA provides some

functionality/classes like TreewithCheckbox
2) Any sample for the same would be helpful./ how to proceed for the same

Question by:rohitdivas
    LVL 37

    Accepted Solution


    Expert Comment

    Yes you should make your own Tree extending from JTree,

    And for nodes as checkboxes or radio buttons you should have your own class implementing TreeCellRenderer (extending from JPanel), and depending upon the level of the node(is it a Level 1 node or Level 2 node) you should add checkbox or radio button on the renderer panel. Also taake care that all radio buttons under one parent should be in one radio button group otherwise you will lose the purpose of having radio buttons.

    As for example, zzynx has already posted the url for example, the url also contains code.

    hope this will help.
    - Kj~

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    wordsFront challenge 8 49
    changeXy challenge 13 41
    json format text only 4 51
    Running Jira on Raspberry PI 2? 3 49
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now