Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Smile kindly help for getting JcheckBoxes in Jtree

    Hi,

    I gone through many codes on internet but wasnt able to understand how can i do that.
    i want to add JCheckbox to my Jtree.
    How can i do that?

    help is appreciated.


    Here is my code for JTree


    Java Code:
        DefaultMutableTreeNode node;
        File[] roots = File.listRoots();
        for (int k=0; k<roots.length; k++)
        {
          node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k])));
    
          top.add(node);
          node.add( new DefaultMutableTreeNode(new Boolean(true)));
        }
    
        m_model = new DefaultTreeModel(top);
        m_tree = new JTree(m_model);
        m_tree.putClientProperty("JTree.lineStyle", "Angled");
    
        TreeCellRenderer renderer = new 
        IconCellRenderer();
        m_tree.setCellRenderer(renderer);
    
        m_tree.addTreeExpansionListener(new 
        DirExpansionListener());
    
        m_tree.addTreeSelectionListener(new 
        DirSelectionListener());
    
        m_tree.getSelectionModel().setSelectionMode(
        TreeSelectionModel.SINGLE_TREE_SELECTION); 
        m_tree.setShowsRootHandles(true); 
        m_tree.setEditable(false);
    
        final JScrollPane s = new JScrollPane();
        s.getViewport().add(m_tree);
    Last edited by Fubarable; 08-07-2010 at 08:14 PM. Reason: Moderator edit: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Move JTree item to another JTree.
    By Melki in forum AWT / Swing
    Replies: 8
    Last Post: 07-09-2009, 12:59 PM
  2. JcheckBoxes as JTree Nodes
    By aneesahamedaa in forum AWT / Swing
    Replies: 11
    Last Post: 02-11-2009, 01:11 AM
  3. Kindly assist me...
    By delbg in forum New To Java
    Replies: 7
    Last Post: 02-05-2009, 04:52 AM
  4. kindly answer the queston in attachment file
    By abhinav_jain09 in forum Advanced Java
    Replies: 11
    Last Post: 09-19-2008, 05:47 PM
  5. Kindly Help me to apply Stylesheet
    By AMATYA-CHANAKYA in forum Advanced Java
    Replies: 0
    Last Post: 03-18-2008, 07:30 AM

Tags for this Thread

Posting Permissions

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