Attaching a checkbox to tree

is it possible in java to attach a checkbox to jtree ?
if so how to do it ?

http://www.java2s.com/Code/Java/Swing-JFC/CheckBoxNodeTreeSample.htm

Similar Messages

  • CheckBox node tree with two diferent kind of nodes

    Hai ,
    I need to build a check box tree with two different kind of nodes , Child and Parent nodes .
    CheckBox node tree with two diferent kind of nodes.
    HOw will i write the renderer and editor for this ?

    Study the method getTreeCellRendererComponent() of the class DefaultTreeCellRenderer.

  • Using checkboxes as tree nodes

    Hi friends,
    can I add checkboxes as tree nodes? if yes, how this can be done?
    Thanks in advances.

    Hi,
    sorry, but this question is not really easy to parse ( I tried two times and gave up ), can you reword it. What is it that you want to synchronize with a tree selection ?
    Frank

  • Checkboxs in Tree

    Hi There,
    I am trying to tweak tree region in apex to include check-boxes.
    Database: 11gR2
    APEX : 4.1
    Browser: IE7 and IE8
    Re: Checkbox on Tree Leaf
    Although I was able to get the check-boxes displayed, it is not functional.
    Any comments are welcome.
    Thank you
    Ligon

    Anyone please?
    I guess trees are a bit tricky for anyone to care respond to :)-
    I hope someone would dare.
    Cheers
    Ligon

  • Adding a checkbox to Trees

    Hi,
    Anyone how to add a checkbox to every item in a tree? I
    wanted to implement something that looks like what is found when
    you install software and get that grey check meaning not all the of
    the children items are not checked. I am not an expert with
    ItemRenderers.

    Write your own table model like
    tm extends DefaultTableModel{
    @Override
    public Class getColumnClass(int index){
      if(index== <your column for boolean>){
          return Boolean.class;
       }else
          return super.getColumnClass(index);
    }

  • Menu option under recursive tree item/folder & checkbox in tree

    Hi,
    I want to present a checkbox next to an item or folder in a recursive tree.
    I didn't see any option to do it so I tried to add a menu and a menu option type checkbox under the node item and note type.
    The issue it does nothing.
    Any ideas?
    THanks,
    Itay

    Hi Akshay,
    Everything mentioned here step by step:
    0. You cannot use check-boxes inside tree, so you have to emulate them with images (or use Table with Tree-like master column -- not discussed in this message)
    1. Create boolean attribute <b>isChecked</b> in node
    2. Create calculated read-only string attribute cbIcon, write following in generated getter function:
    return element.getIsChecked() ?
      "~sapicons/b_okay.gif" : "~sapicons/b_canc.gif";
    or whatever images you are using.
    3. Create & bind action onAction for TreeNode / TreeItem.
      -- apply parameters mapping in wdDoModifyView:
    if ( firstTime )
      final IWDTreeNodeType treeNode = (IWDTreeNodeType)
        view.getElement("<your-tree-node-element-id>");
      treeNode.mappingOfOnAction()
        .addSourceMapping("path", "selectedElement");
      <b>Your action must define parameter with type of your node element and name <i>selectedElement</i></b>
      -- write the following code for handler:
    selectedElement.setIsSelected( !selectedElement.getIsSelected() );
    4. Bind cbIcon attribute as TreeNode / TreeItem image source, bind rest of attributes.
    --Done.
    VS

  • Display Checkbox along Tree node and its child elements

    Experts,
    I want to display a checkbox in front of the Tree displayed in the view. This is used for me to select the child item value for my selection condition.
    let say if the user selects the node, all the child elements will be used for search condition.
    Otherwise, if the node is expanded, then the checkbox selected in the child element will be used for search condition...
    Can u ppl suggest me how to design it, if possible can u share some sample code or procedure to customize the Tree as per the requirement...
    thanx in advance,
    James...

    hi
    please go through this
    <a href="http://integration  of  a  tree  structure  in  a  web  dynpro  table">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/de59f7c2-0401-0010-f08d-8659cef543ce</a>
    Thanks
    Smitha

  • Checkbox on Tree Leaf

    Hi
    I have created a tree in Apex 4 and I am having difficulty in creating a checkbox alongside each leaf of the tree.
    Once checked, i would like to navigate to a specific page with the leaf details.
    Any ideas of how to implement this?
    Thanks.

    Hi vee,
    Sorry to hijack this completed tread.
    I was trying to inject a check-box instead of an image modifying (see below) the code snippet you have provided.
    $('div.tree li a').before('<a href="#"><input type="checkbox" name="edit_link"/></a>');
    $('div.tree li input[name="edit_link"]').click( function() {
      node_id = $(this).parents('li:first').attr('id');
      alert('Selected node: '+node_id)
    });I could see the checkboxes appear however, can not check them. It seems a follow-on action is cancelling out the selection.
    http://apex.oracle.com/pls/otn/f?p=20358:9
    Sorry, I am a JQuery beginner so could not explore much on it. I really appreciate if you could give some direction on how to go about with a solution.
    What I am really after is the ability to add checkboxes to all nodes so that users could do multiple selection, based on which another report region can be filtered.
    Also in IE the JsTree is rendering slow. Does the built-in JsTree support ajax expansion on nodes?
    I really like to implement JsTree my own if it gives me more flexibility, but I guess it will be a big learning curve to transport JSON via ajax for node expansion, etc... but would be wonderful if there is an example available.
    I hope you or somebody else could help.
    Database: 11gR2
    APEX : 4.1
    Browser: IE7 and IE8
    Looking forward for answers....
    Kind Regards
    Ligon
    PS: I did submit this reply around noon AusEstnStand time on Sunday the 4th Aug, but looks like it got disappeared, along with replies I did on three other treads! never-mind I shall type them in again.

  • Display checkbox in TREE

    Using an RS_TREE
    And i'd like to display in one of these fields a checkbox.
    does any one have an id ?
    Maybe a symbols ?
    An icon(no icon for check box)
    any help welcome...

    Stephan,
    I checked the function modules which you had mentioned.
    A word of caution first.
    These are SAP internally released functions and it is not recommended that this be used in customer programs as SAP can change these functions without any prior notice and this might affect your program. More over this function will not be supported by SAP through OSS.
    Maybe when you add a node using RS_TREE_NODE you can set the display attribute SEU_KIND to 'I' for ICON or 'S' for symbol and look for a checkbox ICON or symbol.
    Sorry that I could not help much.
    Regards,
    Vani

  • Checkboxes in tree

    Hi,
    Can anyone send a sample code for keeping check boxes for the last level nodes(leaves) of the tree?
    very urgent. points are assured.
    Regards,
    Srinivas

    Hi check out this coding
    DATA: lt_item_layout TYPE lvc_t_layi,
            ls_item_layout TYPE lvc_s_layi,
           v_alv type ref to cl_gui_alv_tree.
      ls_item_layout-fieldname =v_alv->hierarchy_column_name.
      LS_ITEM_LAYOUT-CLASS   = CL_GUI_COLUMN_TREE=>ITEM_CLASS_CHECKBOX.
      LS_ITEM_LAYOUT-EDITABLE = 'X'.
      APPEND ls_item_layout TO lt_item_layout.
    try this and let me know the result.
    regards
    Ram

  • Help required to attach CO-PA reports to Report Tree.

    HI experts,
    Me and my functional are in urgent need of important information. My functional has generate CO-PA reports and now they have asked us to attach those reports to a report tree. My problem is that I have got the transaction SERP which seems useful in attaching the reports the tree. Kindly suggest what is to be done.
    Points will be rewarded.
    Thanks and Regards,
    Saurabh Chhatre

    Hi,
    Check the following links:
    http://www.sap-img.com/abap/tree-type-report-in-abap.htm
    http://www.sap-img.com/ge002.htm
    Regards,
    Bhaskar

  • ALV Tree - how to put checkbox on the node level?

    Hello everyone!
    I have an AlvTree and I have special column named SEL. That column contains checkboxes. I want to put additional checkboxes at the node level, I need them to create select all option.
    In other words I must somehow create something similar to do_sum option. DO_SUM works for numeric columns, the sum of all rows in current node appears at the top level. So I must do the same but checkbox.
    Are there any ideas?
    Here is my code of creating the tree.
    DATA: g_tree9001 type ref to cl_gui_alv_tree_simple.
    " Here I fill fieldcat...
    create object g_tree9001
          EXPORTING
            i_parent                    = g_doc_cont
            i_node_selection_mode       = cl_gui_column_tree=>node_sel_mode_single
            i_item_selection            = 'X'
            i_no_html_header            = 'X'
            i_no_toolbar                = ''.
    call method g_tree9001->set_table_for_first_display
          EXPORTING
            i_save              = 'A'
            is_variant          = ls_variant
          CHANGING
            it_sort             = gt_sort9001
            it_outtab           = gt_tree9001
            it_fieldcatalog     = gt_treefcat9001.
    My output table gt_tree9001 has sthe following structure:
    BUKRS, KTEXT, SEL, SWERK.
    My sort table gt_sort9001 has 2 rows. Sorting by BUKRS and KTEXT.
    My tree looks like this:
    BUKRS/KTEXT  --- SEL --- SWERK
    +bukrs1 ------------------------------
      -- ktext1 ---  X --- swerk1
      -- ktext2 ---  X --- swerk2
    +bukrs2 ------------------------------
      -- ktext3 ---  X --- swerk3
    I want to get:
    BUKRS/KTEXT  --- SEL --- SWERK
    +bukrs1 ----------X----------------
      -- ktext1 ---  X --- swerk1
      -- ktext2 ---  X --- swerk2
    +bukrs2 ----------X----------------
      -- ktext3 ---  X --- swerk3
    Appreciate any help!

    Hi ,
    Check the below threads, it may give some idea to get check box in the node .
    [LINK1|Check box on left navigation of ALV tree;
    [LINK2|Checkbox ALV Tree CL_GUI_ALV_TREE;
    Regards,
    Saravana.S

  • Problem with Jtree and a checkbox

    Hello,
    I have a problem with my tree implementation.
    I create a tree and i want to add a checkbox in each node.
    this is my code :
    DefaultMutableTreeNode root;
    root = new DefaultMutableTreeNode(new JCheckBox());
    DefaultTreeModel model = new DefaultTreeModel(root);
    _tree = new JTree(model);
    eastpane.add(tree);
    THe problem is that my checkbox doesn't appear. And a message appears
    instead of my checkbox.
    But my tree appears.
    Can anyone help me .
    Thanks

    You can provide a cell renderer to the JTree to paint the checkBox.
    The following code checks or unchecks the box with each click also:
    _tree.setCellRenderer(new DefaultTreeCellRenderer()
      private JCheckBox checkBox = null;
      public Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus)
        // Each node will be drawn as a check box
        if (checkBox == null)
          checkBox  = new JCheckBox();
          checkBox .setBackground(tree.getBackground());
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        checkBox.setText(node.getUserObject().toString());
        checkBox.setSelected(selected);
        return checkBox;
    });

  • Using tree - how to get upper levels

    I create a heirarchical tree based on a couple of tables via a record group i create on the fly.
    I then let the user attach documents to the tree nodes. The problem comes that the node may not exist in the database yet as they can build them as they go. So i need to insert all record on tree into table when they attach a document. I dont want to do this before as i am only interested when they are attaching documents - rather than storing all data that may never be used.
    My problem is when they attach the document i want to find all levels in that particular tree to insert them.
    i.e. if my tree is as follows
    1
    -1b
    2
    -2b
    3
    -3b
    -3c
    and the user attaches against 3c I want to insert 3 into the table, then 3b, then the document against 3b, so i need to find out what its uplevel is in this case 3.
    How is best way to do this? i have NODE_DEPTH property - to know its not top level and NODE VALUE to know the value, and NODE_LABEL to know the description but how can i find my uplevel when its not stored in a table anywhere.

    Cant believe i never found that when searching forms help.
    Thanks

  • Problem with binary search tree

    Hi all, just having troubles with a program im writing.
    My program is based on a binary search tree full of items which are passed in via an input file and then saved to an output file.
    I have written a sellItem method which gets passed in the item and quantity that has been sold which then needs to be changed in the binary tree.
    Here if my sell Item method:
        public void sellItem(Item item, int quantity){
            stockItem = item;
            mQuantity = quantity;
            if (tree.includes(stockItem)){
                int tempQuantity = stockItem.getQuantityInStock();
                tempQuantity -= mQuantity;
            else{
                throw new IllegalArgumentException("The Barcode " + mBarCode + " does NOT exist.");
        }and here is where i am calling it in a test class :
    number1.sellItem(item1, 40);Each item is in this format :
    ABCD, PENCIL, 1, 0.35, 200, 100, 200
    where 200 is the quantity.
    Therefore if i pass 40 into the method the binary search tree should then store the quantity as 160.
    below is a copy of my binary tree :
    public class BSTree extends Object {
        private class TreeNode extends Object{
            public Comparable data;
            public TreeNode left;
            public TreeNode right;
            public TreeNode() {
                this(null);
            public TreeNode(Comparable barCode){
                super();
                data = barCode;
                left = null;
                right = null;
        private TreeNode root; 
        private int nodeCount;
        public BSTree(){
            super();
            root = null;
            nodeCount = 0;
        public boolean isEmpty() {
          return root == null;
        public int size() {
          return nodeCount;
        private TreeNode attach(TreeNode newPointer, TreeNode pointer){
            if (pointer == null){
                nodeCount++;
                return newPointer;
            else {
                Comparable obj1 = (Comparable) newPointer.data;
                Comparable obj2 = (Comparable) pointer.data;
            if (obj1.compareTo(obj2) < 0) //Go left
                pointer.left = attach(newPointer, pointer.left);
            else //Go right
                pointer.right = attach(newPointer, pointer.right);
            return pointer;
        public void insert(Comparable item){
            //Create a new node and initialize
            TreeNode newPointer = new TreeNode(item);
            //Attach it to the tree
            root = attach(newPointer, root);
        public Comparable remove(Comparable key) {
            TreeNode pointer;
            TreeNode parent;
            //Find the node to be removed
            parent = null;
            pointer = root;
            while ((pointer != null) && !key.equals(pointer.data)) {
                parent = pointer;
                if (key.compareTo(pointer.data) <0)
                    pointer = pointer.left;
                else
                    pointer = pointer.right;
            if (pointer == null)
                return null;
            //Orphans
            TreeNode leftSubtree = pointer.left;
            TreeNode rightSubtree = pointer.right;
            if (parent == null)
                root = null;
            else if (key.compareTo(parent.data) < 0)
                parent.left = null;
            else
                parent.right = null;
            //Reattaching any orphans in the left subtree
            if (leftSubtree != null) {
                root = attach(leftSubtree, root);
                nodeCount--;
            //Reattaching any orphans in the right subtree
            if (rightSubtree != null) {
                root = attach(rightSubtree, root);
                nodeCount--;
            nodeCount--;
            return pointer.data;
        private TreeNode search(TreeNode pointer, Comparable key) {
            if (pointer == null)
                return null;
            else if (pointer.data.compareTo(key) == 0)
                return pointer;
            else if (key.compareTo(pointer.data) < 0)
                return search(pointer.left, key);
            else
                return search(pointer.right, key);
        public boolean includes(Comparable key) {
            return (search(root, key) != null);
        public Comparable retrieve(Comparable key) {
            TreeNode pointer;
            pointer = search(root, key);
            if (pointer == null)
                return null;
            else
                return pointer.data;
        public Comparable[] getAllInOrder() {
            Comparable[] list = new Comparable[nodeCount];
            inOrderVisit(root,list,0);
            return list;
        private int inOrderVisit(TreeNode pointer, Comparable[] list, int count) {
            if (pointer != null) {
                count = inOrderVisit(pointer.left, list, count);
                list[count++] = pointer.data;
                count = inOrderVisit(pointer.right, list, count);
            return count;
        public String toString() {
            StringBuffer result = new StringBuffer(100);
            inOrderString(root, result);
            return result.toString();
        private void inOrderString(TreeNode pointer, StringBuffer result) {
            if (pointer != null) {
                inOrderString(pointer.left, result);
                result.append(pointer.data.toString() + "\n");
                inOrderString(pointer.right, result);
    }Thanks for everyones help. Keep in mind i'm very new to java.

    Hi all, just having troubles with a program im writing.
    My program is based on a binary search tree full of items which are passed in via an input file and then saved to an output file.
    I have written a sellItem method which gets passed in the item and quantity that has been sold which then needs to be changed in the binary tree.
    Here if my sell Item method:
        public void sellItem(Item item, int quantity){
            stockItem = item;
            mQuantity = quantity;
            if (tree.includes(stockItem)){
                int tempQuantity = stockItem.getQuantityInStock();
                tempQuantity -= mQuantity;
            else{
                throw new IllegalArgumentException("The Barcode " + mBarCode + " does NOT exist.");
        }and here is where i am calling it in a test class :
    number1.sellItem(item1, 40);Each item is in this format :
    ABCD, PENCIL, 1, 0.35, 200, 100, 200
    where 200 is the quantity.
    Therefore if i pass 40 into the method the binary search tree should then store the quantity as 160.
    below is a copy of my binary tree :
    public class BSTree extends Object {
        private class TreeNode extends Object{
            public Comparable data;
            public TreeNode left;
            public TreeNode right;
            public TreeNode() {
                this(null);
            public TreeNode(Comparable barCode){
                super();
                data = barCode;
                left = null;
                right = null;
        private TreeNode root; 
        private int nodeCount;
        public BSTree(){
            super();
            root = null;
            nodeCount = 0;
        public boolean isEmpty() {
          return root == null;
        public int size() {
          return nodeCount;
        private TreeNode attach(TreeNode newPointer, TreeNode pointer){
            if (pointer == null){
                nodeCount++;
                return newPointer;
            else {
                Comparable obj1 = (Comparable) newPointer.data;
                Comparable obj2 = (Comparable) pointer.data;
            if (obj1.compareTo(obj2) < 0) //Go left
                pointer.left = attach(newPointer, pointer.left);
            else //Go right
                pointer.right = attach(newPointer, pointer.right);
            return pointer;
        public void insert(Comparable item){
            //Create a new node and initialize
            TreeNode newPointer = new TreeNode(item);
            //Attach it to the tree
            root = attach(newPointer, root);
        public Comparable remove(Comparable key) {
            TreeNode pointer;
            TreeNode parent;
            //Find the node to be removed
            parent = null;
            pointer = root;
            while ((pointer != null) && !key.equals(pointer.data)) {
                parent = pointer;
                if (key.compareTo(pointer.data) <0)
                    pointer = pointer.left;
                else
                    pointer = pointer.right;
            if (pointer == null)
                return null;
            //Orphans
            TreeNode leftSubtree = pointer.left;
            TreeNode rightSubtree = pointer.right;
            if (parent == null)
                root = null;
            else if (key.compareTo(parent.data) < 0)
                parent.left = null;
            else
                parent.right = null;
            //Reattaching any orphans in the left subtree
            if (leftSubtree != null) {
                root = attach(leftSubtree, root);
                nodeCount--;
            //Reattaching any orphans in the right subtree
            if (rightSubtree != null) {
                root = attach(rightSubtree, root);
                nodeCount--;
            nodeCount--;
            return pointer.data;
        private TreeNode search(TreeNode pointer, Comparable key) {
            if (pointer == null)
                return null;
            else if (pointer.data.compareTo(key) == 0)
                return pointer;
            else if (key.compareTo(pointer.data) < 0)
                return search(pointer.left, key);
            else
                return search(pointer.right, key);
        public boolean includes(Comparable key) {
            return (search(root, key) != null);
        public Comparable retrieve(Comparable key) {
            TreeNode pointer;
            pointer = search(root, key);
            if (pointer == null)
                return null;
            else
                return pointer.data;
        public Comparable[] getAllInOrder() {
            Comparable[] list = new Comparable[nodeCount];
            inOrderVisit(root,list,0);
            return list;
        private int inOrderVisit(TreeNode pointer, Comparable[] list, int count) {
            if (pointer != null) {
                count = inOrderVisit(pointer.left, list, count);
                list[count++] = pointer.data;
                count = inOrderVisit(pointer.right, list, count);
            return count;
        public String toString() {
            StringBuffer result = new StringBuffer(100);
            inOrderString(root, result);
            return result.toString();
        private void inOrderString(TreeNode pointer, StringBuffer result) {
            if (pointer != null) {
                inOrderString(pointer.left, result);
                result.append(pointer.data.toString() + "\n");
                inOrderString(pointer.right, result);
    }Thanks for everyones help. Keep in mind i'm very new to java.

Maybe you are looking for

  • Change WEB UI Text

    Hi Gurus I want to change the description of the "Search: Service Order" view which is visible from the WEB UI. I would have thought modifying the Logical Link would have made this possible. Is this only possible via Custom Code? If so where must I m

  • URGENT - HANDLING SOUNDS IN JWS

    Hi I am done an application with runs fine in Java Web start. I have used some sound files in that which playing using JMF. I have jared all the sound files and which downloading properly in client machine. But i am getting the following Exception wh

  • Very Basic Objective-C issue, I am sure

    So I picked up a book on ojective-c namely Mr. Kochan's, and have been trying to work through the exercises and examples. I ran into my first problem that I haven't been able to solve myself. The error says that the object I tried to create "point" i

  • Search user vith DBMS_LDAP.search_s  return LdapErr: DSID-0C090627 error

    Hi all, I have a problem. I need to search a user in my LDAP AD. I want to check if my user exists without using password. I wrote this procedure create or replace procedure search_user_ldap IS l_retval                     PLS_INTEGER; l_session     

  • Problems with netinfo in 10.5

    We have 10.5.5. We keep getting this error in the system log: Sep 29 09:19:37 Xdata02 org.openldap.slapd[45483]: Unrecognized database type (netinfo) Sep 29 09:19:37 Xdata02 com.apple.launchd[1] (org.openldap.slapd[45483]): Exited with exit code: 1 S