Java Swing: Need a good quality developed JTree with checkboxes

前端 未结 3 1866
面向向阳花
面向向阳花 2020-12-03 13:33

I was looking for a a JTree implementation, that contains checkboxes and which:

  • When you select one node, all its successors in the tree are automatically s

3条回答
  •  爱一瞬间的悲伤
    2020-12-03 14:24

    Can be solution without map structure.

    MouseAdapter ml = new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                if ( e.getClickCount() == 1 )
                {
                    TreePath selPath = m_xTree.getPathForLocation(e.getX(), e.getY());
                    if(selPath==null) return;
                    else if (selPath!=null && selPath.getPathCount()>=1)
                    {
                        DataItem xDIClicked = (DataItem)( selPath.getPathComponent(selPath.getPathCount()-1) );
                        xDIClicked.setIsSelectedByCheckbox( !xDIClicked.getIsSelectedByCheckbox() );
                        m_xTree.repaint();
                    }
                }
            }
        };
        m_xTree.addMouseListener(ml);
    

    So xDIClicked returned by getPathComponent() is JTree Model's data item. And each DataItem contains checked property.

提交回复
热议问题