[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1025
  • Last Modified:

Tree with checkbox nodes and radiobutton subnodes.!

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

thanks,
rdh
            
            
0
rohitdivas
Asked:
rohitdivas
1 Solution
 
zzynxSoftware engineerCommented:
0
 
kamaljeetsCommented:
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~
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now