Results 1 to 11 of 11
  1. #1
    shajuantony is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Smile JCheckbox in Jtree

    Hai

    Please help me to solve this, i need JCheckbox as a node in Jtree
    and i make some code with the following. it is working but i can't select the chckbox as per the value from the resultset



    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Font;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.MouseEvent;
    import java.util.Enumeration;
    import java.util.EventObject;
    import java.util.Hashtable;
    import java.util.List;
    import java.util.Vector;
    import java.sql.ResultSet;
    import javax.swing.AbstractCellEditor;
    import javax.swing.DefaultCellEditor;
    import javax.swing.Icon;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JOptionPane;
    import javax.swing.JTree;
    import javax.swing.UIManager;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableColumnModel;
    import javax.swing.text.Position;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeCellEditor;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreeNode;
    import javax.swing.tree.TreePath;
    import javax.swing.tree.TreeSelectionModel;
    import javax.swing.JDialog;
    import javax.swing.JPanel;
    import java.awt.GridBagLayout;
    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.io.File;
    import java.util.ArrayList;
    import javax.swing.JButton;
    import javax.swing.JSplitPane;



    import java.awt.event.ActionListener;
    import java.awt.font.FontRenderContext;
    public class UserPermission extends JDialog implements ActionListener,TreeSelectionListener
    {

    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private ResultSet rs =null; // @jve:decl-index=0:
    private JPanel panMain = null; // @jve:decl-index=0:visual-constraint="15,62"
    //private JTree jTree = null;
    private CheckBoxTree jTree = null;
    private DefaultMutableTreeNode top = null;
    private DefaultMutableTreeNode node=null; // @jve:decl-index=0:
    protected DefaultTreeModel m_model=null;
    protected JCheckBox chk = new JCheckBox("");
    private JButton jButton = null;
    private JButton btnCancel = null;
    private JScrollPane jScrollPane = null; // @jve:decl-index=0:visual-constraint="582,197"
    private JSplitPane jSplitPane = null; // @jve:decl-index=0:visual-constraint="569,269"
    private JScrollPane empScrollPane = null; // @jve:decl-index=0:visual-constraint="620,91"
    private JTree treeEmp = null;
    private String nodeName=null;
    private String menuName=null;
    private String usrId="";
    private ArrayList selectedMenu=new ArrayList(); // @jve:decl-index=0:
    public UserPermission(JFrame obj)
    {
    super(obj,"User Permission",true);
    add(getPanMain());
    }

    public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)
    treeEmp.getLastSelectedPathComponent();


    if (node == null ) return;
    Object nodeInfo = node.getUserObject();
    nodeName=nodeInfo.toString();
    getUserId();
    getUserPermission();


    }
    public TreePath[] getPaths(JTree tree, boolean expanded) {
    TreeNode root = (TreeNode)tree.getModel().getRoot();

    // Create array to hold the treepaths
    List list = new ArrayList();

    // Traverse tree from root adding treepaths for all nodes to list
    getPaths(tree, new TreePath(root), expanded, list);

    // Convert list to array
    return (TreePath[])list.toArray(new TreePath[list.size()]);
    }

    public void getPaths(JTree tree, TreePath parent, boolean expanded, List list) {
    // Return if node is not expanded
    if (expanded && !tree.isVisible(parent)) {
    return;
    }

    // Add node to list
    list.add(parent);

    // Create paths for all children
    TreeNode node = (TreeNode)parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
    for (Enumeration e=node.children(); e.hasMoreElements(); ) {
    TreeNode n = (TreeNode)e.nextElement();

    TreePath path = parent.pathByAddingChild(n);

    getPaths(tree, path, expanded, list);
    }
    }
    }

    public void actionPerformed(ActionEvent ae)
    {
    try
    {
    if(ae.getSource()==jButton)
    {
    selectedMenu.clear();
    TreePath[] path= getPaths(jTree, false);
    String name="";
    for(int i=0;i<path.length;i++)
    {
    if(path[i].toString().indexOf("true")>0)
    {
    JOptionPane.showMessageDialog(null,path[i].toString());
    name=path[i].toString().substring(path[i].toString().lastIndexOf("[")+1,path[i].toString().lastIndexOf("/"));
    selectedMenu.add(String.valueOf(name));
    }
    }
    if(selectedMenu.size()<1)
    {
    JOptionPane.showMessageDialog(null,"There is no changes to update!");
    dispose();
    }
    else
    {
    usrId="";
    getUserId();

    if(usrId.trim().length()==0)
    return;
    String sql="select count(*) as cnt from user_permission where um_id='"+usrId+"'";
    rs=Global.nlaDbase.getRecordSet(sql);
    boolean exist=false;
    if(rs.next())
    {
    if(Integer.parseInt(rs.getString("cnt"))>0)
    exist=true;
    else
    exist=false;
    }
    rs.close();
    if(exist)
    Global.nlaDbase.Update("delete from user_permission where um_id='"+usrId+"'");
    String menuId="",menuSub="";
    for(int i=0;i<selectedMenu.size();i++)
    {
    sql="select mm_id,mm_submenu from menu_master where mm_menuname='"+String.valueOf(selectedMenu.get(i)) +"'";
    rs=Global.nlaDbase.getRecordSet(sql);
    if(rs.next())
    {
    menuId=rs.getString("mm_id");
    menuSub=rs.getString("mm_submenu");
    }
    rs.close();


    Global.nlaDbase.Update("insert into user_permission (um_id,mm_id,mm_menuname,mm_submenu) values ('"+usrId+"','"+menuId+"','"+String.valueOf(select edMenu.get(i))+"','"+menuSub+"')");
    }
    JOptionPane.showMessageDialog(null,"The Permission(s) has been updated");
    dispose();
    }
    }
    else if(ae.getSource()==btnCancel)
    {
    dispose();




    }
    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,ex.toString());
    ex.printStackTrace();
    }
    }
    private void getUserId()
    {
    try
    {
    String sql="select um_id from usermaster where um_name='"+nodeName+"'";
    rs=Global.nlaDbase.getRecordSet(sql);
    if(rs.next())
    {
    usrId=rs.getString("um_id");
    }
    rs.close();
    if(usrId.trim().length()==0)
    return;
    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,ex.toString());
    ex.printStackTrace();
    }
    }
    private void getUserPermission()
    {
    Vector v=new Vector();
    try
    {
    rs.close();
    //JOptionPane.showMessageDialog(null,usrId);
    rs=Global.nlaDbase.getRecordSet("select * from user_permission where um_id='"+usrId+"'");
    while(rs.next())
    {
    v.add(rs.getString("mm_menuname"));

    }

    rs.close();

    /*TreeNode root = (TreeNode)jTree.getModel().getRoot();
    TreePath parent=new TreePath(root);
    TreeNode node = (TreeNode)parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
    for (Enumeration e=node.children(); e.hasMoreElements(); )
    {
    TreeNode n = (TreeNode)e.nextElement();

    TreePath path = parent.pathByAddingChild(n);



    //JOptionPane.showMessageDialog(null,"Called :"+path.toString());
    }
    }*/




    for(int i=0;i<v.size();i++)
    {
    TreePath p = findByName(jTree, new String[]{"M"});
    //if(p!= null)
    JOptionPane.showMessageDialog(null," Inside For"+p.toString());

    }

    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,ex.toString());
    ex.printStackTrace();
    }
    }

    public TreePath findByName(JTree tree, String[] names) {
    TreeNode root = (TreeNode)tree.getModel().getRoot();
    JOptionPane.showMessageDialog(null,"Inside findByName ");
    return find2(tree, new TreePath(root), names, 0, true);
    }

    private TreePath find2(JTree tree, TreePath parent, Object[] nodes, int depth, boolean byName)
    {
    try
    {
    TreeNode node = (TreeNode)parent.getLastPathComponent();
    Object o = node;
    // If by name, convert node to a string
    if (byName) {
    o = o.toString();
    }

    JOptionPane.showMessageDialog(null,"Test");

    // If equal, go down the branch
    if (o.equals(nodes[depth])) {
    // If at end, return match
    if (depth == nodes.length-1) {
    return parent;
    }

    // Traverse children
    if (node.getChildCount() >= 0) {
    for (Enumeration e=node.children(); e.hasMoreElements(); ) {
    TreeNode n = (TreeNode)e.nextElement();
    TreePath path = parent.pathByAddingChild(n);
    for(int x=0;x<nodes.length;x++)
    JOptionPane.showMessageDialog(null," Given String to Find "+String.valueOf(nodes[x]));
    TreePath result = find2(tree, path, nodes, depth+1, byName);
    // Found a match
    if (result != null) {
    return result;
    }
    }
    }
    }

    // No match at this branch
    return null;
    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,"Inside : "+ex.toString());
    ex.printStackTrace();
    return null;
    }
    }


    /**
    * This method initializes panMain
    *
    * @return javax.swing.JPanel
    */
    private JPanel getPanMain() {
    if (panMain == null) {
    panMain = new JPanel();
    panMain.setLayout(null);
    //panMain.setSize(new Dimension(445, 465));
    panMain.setSize(new Dimension(445, 470));
    panMain.add(getJTree(), null);
    panMain.add(getJButton(), null);
    panMain.add(getBtnCancel(), null);
    panMain.add(getJSplitPane(),null);
    }
    return panMain;
    }

    private void expand(JTree tree) {
    DefaultMutableTreeNode root =
    (DefaultMutableTreeNode)tree.getModel().getRoot();
    java.util.Enumeration e = root.breadthFirstEnumeration();
    while(e.hasMoreElements()) {
    DefaultMutableTreeNode node =
    (DefaultMutableTreeNode)e.nextElement();
    if(node.isLeaf()) continue;
    int row = tree.getRowForPath(new TreePath(node.getPath()));
    tree.expandRow(row);
    }
    }


    private JTree getJTree() {
    if (jTree == null)
    {
    try
    {
    setNode();
    expand(jTree);
    CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
    jTree.setCellRenderer(renderer);


    jTree.setCellEditor(new CheckBoxNodeEditor(jTree));

    jTree.setEditable(true);
    jTree.putClientProperty("JTree.lineStyle", "Angled");

    jTree.setShowsRootHandles(true);
    jTree.addTreeSelectionListener(this);

    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,ex.toString());
    ex.printStackTrace();
    }


    }
    return jTree;
    }

    /**
    * This method initializes jButton
    *
    * @return javax.swing.JButton
    */
    private JButton getJButton() {
    if (jButton == null) {
    jButton = new JButton();
    //jButton.setBounds(new Rectangle(283, 436, 74, 20));
    jButton.setBounds(new Rectangle(283, 470, 74, 20));
    jButton.setText("Update");
    jButton.addActionListener(this);
    }
    return jButton;
    }



    /**
    * This method initializes btnCancel
    *
    * @return javax.swing.JButton
    */
    private JButton getBtnCancel() {
    if (btnCancel == null) {
    btnCancel = new JButton();
    //btnCancel.setBounds(new Rectangle(365, 436, 74, 20));
    btnCancel.setBounds(new Rectangle(365, 470, 74, 20));
    btnCancel.setText("Cancel");
    btnCancel.addActionListener(this);
    }
    return btnCancel;
    }



    /**
    * This method initializes jScrollPane
    *
    * @return javax.swing.JScrollPane
    */
    private JScrollPane getJScrollPane() {
    if (jScrollPane == null) {
    jScrollPane = new JScrollPane(jTree,JScrollPane.VERTICAL_SCROLLBAR_A LWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jScrollPane.setBounds(90, 51, 483, 301);
    }
    return jScrollPane;
    }



    /**
    * This method initializes jSplitPane
    *
    * @return javax.swing.JSplitPane
    */
    private JSplitPane getJSplitPane() {
    if (jSplitPane == null) {
    jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    jSplitPane.setTopComponent(getEmpScrollPane());
    jSplitPane.setBottomComponent(getJScrollPane());
    jSplitPane.setSize(new Dimension(450, 450));
    jSplitPane.setDividerLocation(100);
    }
    return jSplitPane;
    }



    /**
    * This method initializes empScrollPane
    *
    * @return javax.swing.JScrollPane
    */
    private JScrollPane getEmpScrollPane() {
    if (empScrollPane == null) {
    empScrollPane = new JScrollPane();
    empScrollPane.setSize(new Dimension(245, 250));
    empScrollPane.setViewportView(getTreeEmp());
    }
    return empScrollPane;
    }



    /**
    * This method initializes treeEmp
    *
    * @return javax.swing.JTree
    */
    private JTree getTreeEmp() {
    if (treeEmp == null) {

    try
    {

    DefaultMutableTreeNode top =
    new DefaultMutableTreeNode("User List");

    rs=Global.nlaDbase.getRecordSet("select um_name as name from usermaster where um_id <>md5('admin')");
    while(rs.next())
    {
    top.add(new DefaultMutableTreeNode(rs.getString("name")));
    }
    treeEmp = new JTree(top);


    rs.close();

    treeEmp.setEditable(false);
    treeEmp.putClientProperty("JTree.lineStyle", "Angled");

    treeEmp.setShowsRootHandles(true);
    treeEmp.addTreeSelectionListener(this);


    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,ex.toString());
    ex.printStackTrace();
    }


    }
    return treeEmp;
    }


    protected void setNode()
    {
    try
    {
    String sl="SELECT * FROM menu_master where length(trim(mm_submenu))=0 and mm_menutype='main'";
    ArrayList mainMenu=new ArrayList();
    ArrayList subMenu=new ArrayList();
    ArrayList vect=new ArrayList();
    ArrayList master=new ArrayList();

    Vector rootVector=new Vector();
    Vector accessVector=new Vector();
    rs=Global.nlaDbase.getRecordSet(sl);
    while(rs.next())
    {
    mainMenu.add(String.valueOf(rs.getString("MM_Menun ame")));
    }
    rs.close();
    for(int i=0;i<mainMenu.size();i++)
    {

    sl="SELECT * FROM menu_master where mm_submenu='"+mainMenu.get(i)+"' and mm_menutype='Sub'";
    rs=Global.nlaDbase.getRecordSet(sl);
    while(rs.next())
    {
    subMenu.add(String.valueOf(rs.getString("MM_Menuna me")));
    }
    rs.close();
    for(int j=0;j<subMenu.size();j++)
    {
    master.add(new CheckBoxNode(String.valueOf(subMenu.get(j)), false));
    }

    vect.add(new NamedVector(String.valueOf(mainMenu.get(i)),master ));

    subMenu.clear();
    accessVector.clear();
    master.clear();
    }
    mainMenu.clear();
    rootVector.add(new NamedVector("Root", vect));
    //jTree = new JTree(rootVector);
    jTree = new CheckBoxTree(rootVector);

    rootVector.clear();
    vect.clear();
    }
    catch(Exception ex)
    {
    JOptionPane.showMessageDialog(null,ex.toString());
    ex.printStackTrace();
    }
    }

    }
    class CheckBoxNode
    {
    String text;

    boolean selected;

    public CheckBoxNode(String text, boolean selected) {
    this.text = text;
    this.selected = selected;
    }

    public boolean isSelected() {
    return selected;
    }

    public void setSelected(boolean newValue) {
    selected = newValue;
    }

    public String getText() {
    return text;
    }

    public void setText(String newValue) {
    text = newValue;
    }

    public String toString() {
    return getClass().getName() + "[" + text + "/" + selected + "]";
    }
    }

    class NamedVector extends Vector {
    String name;

    public NamedVector(String name) {
    this.name = name;
    }

    public NamedVector(String name, Object elements[])
    {
    this.name = name;
    /*for (int i = 0, n = elements.length; i < n; i++) {
    add(elements[i]);
    }*/
    }

    public NamedVector(String name, ArrayList elements)
    {
    this.name = name;
    for (int i = 0, n = elements.size(); i < n; i++) {
    add(elements.get(i));
    }
    }


    public String toString() {
    return "[" + name + "]";
    }
    }

    class CheckBoxNodeEditor extends AbstractCellEditor implements TreeCellEditor {

    CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();

    protected transient int offset;
    protected int clickCountToStart = 1;

    ChangeEvent changeEvent = null;

    JTree tree;

    public CheckBoxNodeEditor(JTree tree) {
    this.tree = tree;
    }

    public Object getCellEditorValue() {
    JCheckBox checkbox = renderer.getLeafRenderer();
    CheckBoxNode checkBoxNode = new CheckBoxNode(checkbox.getText(),
    checkbox.isSelected());
    return checkBoxNode;
    }

    public boolean isCellEditable(EventObject event)
    {
    boolean returnValue = false;
    if (event instanceof MouseEvent) {
    MouseEvent mouseEvent = (MouseEvent) event;
    TreePath path = tree.getPathForLocation(mouseEvent.getX(),
    mouseEvent.getY());
    if (path != null) {
    Object node = path.getLastPathComponent();
    if ((node != null) && (node instanceof DefaultMutableTreeNode)) {
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
    Object userObject = treeNode.getUserObject();
    returnValue = ((treeNode.isLeaf()) && (userObject instanceof CheckBoxNode));
    }
    }
    }
    return returnValue;


    }



    public Component getTreeCellEditorComponent(JTree tree, Object value,
    boolean selected, boolean expanded, boolean leaf, int row) {

    Component editor = renderer.getTreeCellRendererComponent(tree, value,
    true, expanded, leaf, row, true);

    // editor always selected / focused
    ItemListener itemListener = new ItemListener() {
    public void itemStateChanged(ItemEvent itemEvent) {
    if (stopCellEditing()) {
    fireEditingStopped();
    }
    }
    };
    if (editor instanceof JCheckBox) {
    ((JCheckBox) editor).addItemListener(itemListener);
    }

    return editor;
    }
    }

    class CheckBoxNodeRenderer implements TreeCellRenderer {
    private JCheckBox leafRenderer = new JCheckBox();

    private DefaultTreeCellRenderer nonLeafRenderer = new DefaultTreeCellRenderer();

    Color selectionBorderColor, selectionForeground, selectionBackground,
    textForeground, textBackground;

    protected JCheckBox getLeafRenderer() {

    return leafRenderer;
    }

    public CheckBoxNodeRenderer() {
    Font fontValue;
    fontValue = UIManager.getFont("Tree.font");
    if (fontValue != null) {
    leafRenderer.setFont(fontValue);
    }
    Boolean booleanValue = (Boolean) UIManager
    .get("Tree.drawsFocusBorderAroundIcon");
    leafRenderer.setFocusPainted((booleanValue != null)
    && (booleanValue.booleanValue()));


    selectionBorderColor = UIManager.getColor("Tree.selectionBorderColor");
    selectionForeground = UIManager.getColor("Tree.selectionForeground");
    selectionBackground = UIManager.getColor("Tree.selectionBackground");
    textForeground = UIManager.getColor("Tree.textForeground");
    textBackground = UIManager.getColor("Tree.textBackground");
    }

    public Component getTreeCellRendererComponent(JTree tree, Object value,
    boolean selected, boolean expanded, boolean leaf, int row,
    boolean hasFocus) {

    Component returnValue;
    if (leaf) {

    String stringValue = tree.convertValueToText(value, selected,
    expanded, leaf, row, false);
    leafRenderer.setText(stringValue);
    leafRenderer.setSelected(false);

    leafRenderer.setEnabled(tree.isEnabled());

    /* if (selected) {
    leafRenderer.setForeground(selectionForeground);
    leafRenderer.setBackground(selectionBackground);
    } else {
    leafRenderer.setForeground(textForeground);
    leafRenderer.setBackground(textBackground);
    }*/

    if ((value != null) && (value instanceof DefaultMutableTreeNode)) {
    Object userObject = ((DefaultMutableTreeNode) value)
    .getUserObject();
    if (userObject instanceof CheckBoxNode) {
    CheckBoxNode node = (CheckBoxNode) userObject;
    leafRenderer.setText(node.getText());
    leafRenderer.setSelected(node.isSelected());
    }
    }
    returnValue = leafRenderer;
    } else {
    returnValue = nonLeafRenderer.getTreeCellRendererComponent(tree,
    value, selected, expanded, leaf, row, hasFocus);
    }
    return returnValue;
    }
    }


    please help me

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    what are CheckBoxTree and Global?

    what means "as per the value from the resultset"?

  3. #3
    shajuantony is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Smile JCheckbox

    herewith i have enclosed
    Attached Files Attached Files

  4. #4
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    i think you need to work out a cellEditor that may extends AbstractCellEditor implements TreeCellEditor
    Last edited by mtyoung; 04-09-2009 at 11:56 AM.

  5. #5
    shajuantony is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Default JCheckbox

    please help me for this issue

    to place jcheckbox as a node in jtree

    thanks

  6. #6
    shajuantony is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Default

    the problem solved

  7. #7
    shajuantony is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Default

    thanks to all
    and now i need the following

    1) how do i display a .html file inside a swing
    2) how do i print report in a dotmatrix printer

    thanks

  8. #8
    icsbcn is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Default ???

    Quote Originally Posted by shajuantony View Post
    the problem solved
    How you solved that please?

    Thank you.

  9. #9
    shajuantony is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Default JCheckbox in JTree

    Hai,

    i don't have that code rightnow, but i will give u soon, give me u r mail id

    shaju
    9791800608

  10. #10
    shajuantony is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Smile JCheckbox in JTree

    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.tree.DefaultTreeSelectionModel;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreePath;
    import javax.swing.tree.TreeSelectionModel;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Stack;
    import java.util.Vector;


    public class CheckBoxTreeSelectionModel extends
    DefaultTreeSelectionModel {
    private TreeModel _model;
    private boolean _digIn = true;
    private CheckBoxTree _tree;

    private boolean _singleEventMode = false;

    public CheckBoxTreeSelectionModel(TreeModel model) {
    _model = model;
    setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_ TREE_SELECTION);
    }

    void setTree(CheckBoxTree tree) {
    _tree = tree;
    }

    public CheckBoxTreeSelectionModel(TreeModel model, boolean digIn) {
    _model = model;
    _digIn = digIn;
    }

    public TreeModel getModel() {
    return _model;
    }

    public void setModel(TreeModel model) {
    _model = model;
    }

    /**
    * Gets the dig-in mode. If the CheckBoxTree is in dig-in mode, checking the parent node
    * will check all the children. Correspondingly, getSelectionPaths() will only return the
    * parent tree path. If not in dig-in mode, each tree node can be checked or unchecked independently
    *
    * @return true or false.
    */
    public boolean isDigIn() {
    return _digIn;
    }

    /**
    * Sets the dig-in mode. If the CheckBoxTree is in dig-in mode, checking the parent node
    * will check all the children. Correspondingly, getSelectionPaths() will only return the
    * parent tree path. If not in dig-in mode, each tree node can be checked or unchecked independently
    *
    * @param digIn true to enable dig-in mode. False to disable it.
    */
    public void setDigIn(boolean digIn) {
    _digIn = digIn;
    }

    /**
    * Tests whether there is any unselected node in the subtree of given path.
    *
    * @param path check if the path is partially selected.
    * @return true i fpartially. Otherwise false.
    */
    public boolean isPartiallySelected(TreePath path) {
    if (isPathSelected(path, true))
    return false;
    TreePath[] selectionPaths = getSelectionPaths();
    if (selectionPaths == null)
    return false;
    for (TreePath selectionPath : selectionPaths) {
    if (isDescendant(selectionPath, path))
    return true;
    }
    return false;
    }

    /**
    * Tells whether given path is selected. if dig is true,
    * then a path is assumed to be selected, if one of its ancestor is selected.
    *
    * @param path check if the path is selected.
    * @param digIn whether we will check its descendants.
    * @return true if the path is selected.
    */
    public boolean isPathSelected(TreePath path, boolean digIn) {
    if (!digIn)
    return super .isPathSelected(path);

    while (path != null && !super .isPathSelected(path)) {
    path = path.getParentPath();
    }
    return path != null;
    }

    /**
    * is path1 descendant of path2.
    *
    * @param path1 the first path
    * @param path2 the second path
    * @return true if the first path is the descendant of the second path.
    */
    private boolean isDescendant(TreePath path1, TreePath path2) {
    Object obj1[] = path1.getPath();
    Object obj2[] = path2.getPath();
    for (int i = 0; i < obj2.length; i++) {
    if (obj1[i] != obj2[i])
    return false;
    }
    return true;
    }

    private boolean _fireEvent = true;

    @SuppressWarnings({"RawUseOfParameterizedType"})
    @Override
    protected void notifyPathChange(Vector changedPaths,
    TreePath oldLeadSelection) {
    if (_fireEvent) {
    super .notifyPathChange(changedPaths, oldLeadSelection);
    }
    }

    /**
    * Overrides the method in DefaultTreeSelectionModel to consider digIn mode.
    *
    * @param pPaths the tree paths to be selected.
    */
    @Override
    public void setSelectionPaths(TreePath[] pPaths) {
    if (!isDigIn()) {
    super .setSelectionPaths(pPaths);
    } else {
    clearSelection();
    addSelectionPaths(pPaths);
    }
    }

    /**
    * Overrides the method in DefaultTreeSelectionModel to consider digIn mode.
    *
    * @param paths the tree paths to be added to selection paths.
    */
    @Override
    public void addSelectionPaths(TreePath[] paths) {
    if (!isDigIn()) {
    super .addSelectionPaths(paths);
    return;
    }

    boolean fireEventAtTheEnd = false;
    if (isSingleEventMode() && _fireEvent) {
    _fireEvent = false;
    fireEventAtTheEnd = true;
    }

    try {
    // unselect all descendants of paths[]
    List<TreePath> toBeRemoved = new ArrayList<TreePath>();
    for (TreePath path : paths) {
    TreePath[] selectionPaths = getSelectionPaths();
    if (selectionPaths == null)
    break;
    for (TreePath selectionPath : selectionPaths) {
    if (isDescendant(selectionPath, path))
    toBeRemoved.add(selectionPath);
    }
    }
    if (toBeRemoved.size() > 0) {
    delegateRemoveSelectionPaths(toBeRemoved
    .toArray(new TreePath[toBeRemoved.size()]));
    }

    // if all siblings are selected then unselect them and select parent recursively
    // otherwize just select that path.
    for (TreePath path : paths) {
    TreePath temp = null;
    while (areSiblingsSelected(path)) {
    temp = path;
    if (path.getParentPath() == null)
    break;
    path = path.getParentPath();
    }
    if (temp != null) {
    if (temp.getParentPath() != null) {
    addSelectionPath(temp.getParentPath());
    } else {
    if (!isSelectionEmpty()) {
    removeSelectionPaths(getSelectionPaths());
    }
    delegateAddSelectionPaths(new TreePath[] { temp });
    }
    } else {
    delegateAddSelectionPaths(new TreePath[] { path });
    }
    }
    } finally {
    _fireEvent = true;
    if (isSingleEventMode() && fireEventAtTheEnd) {
    notifyPathChange(paths, true, paths[0]);
    }
    }
    }

    /**
    * tells whether all siblings of given path are selected.
    *
    * @param path the tree path
    * @return true if the siblings are all selected.
    */
    private boolean areSiblingsSelected(TreePath path) {
    TreePath parent = path.getParentPath();
    if (parent == null)
    return true;
    Object node = path.getLastPathComponent();
    Object parentNode = parent.getLastPathComponent();

    int childCount = _model.getChildCount(parentNode);
    for (int i = 0; i < childCount; i++) {
    Object childNode = _model.getChild(parentNode, i);
    if (childNode == node)
    continue;
    TreePath childPath = parent.pathByAddingChild(childNode);
    if (_tree != null && !_tree.isCheckBoxVisible(childPath))
    continue;
    if (!isPathSelected(childPath)) {
    return false;
    }
    }
    return true;
    }

    @Override
    public void removeSelectionPaths(TreePath[] paths) {
    if (!isDigIn()) {
    super .removeSelectionPaths(paths);
    return;
    }

    List<TreePath> toBeRemoved = new ArrayList<TreePath>();
    for (TreePath path : paths) {
    if (path.getPathCount() == 1) {
    toBeRemoved.add(path);
    } else {
    toggleRemoveSelection(path);
    }
    }
    if (toBeRemoved.size() > 0) {
    delegateRemoveSelectionPaths(toBeRemoved
    .toArray(new TreePath[toBeRemoved.size()]));
    }
    }

    /**
    * If any ancestor node of given path is selected then unselect
    * it and selection all its descendants except given path and descendants.
    * Otherwise just unselect the given path
    *
    * @param path the tree path
    */
    private void toggleRemoveSelection(TreePath path) {
    boolean fireEventAtTheEnd = false;
    if (isSingleEventMode() && _fireEvent) {
    _fireEvent = false;
    fireEventAtTheEnd = true;
    }

    try {
    Stack<TreePath> stack = new Stack<TreePath>();
    TreePath parent = path.getParentPath();
    while (parent != null && !isPathSelected(parent)) {
    stack.push(parent);
    parent = parent.getParentPath();
    }
    if (parent != null)
    stack.push(parent);
    else {
    delegateRemoveSelectionPaths(new TreePath[] { path });
    return;
    }

    List<TreePath> toBeAdded = new ArrayList<TreePath>();
    while (!stack.isEmpty()) {
    TreePath temp = stack.pop();
    TreePath peekPath = stack.isEmpty() ? path : stack
    .peek();
    Object node = temp.getLastPathComponent();
    Object peekNode = peekPath.getLastPathComponent();
    int childCount = _model.getChildCount(node);
    for (int i = 0; i < childCount; i++) {
    Object childNode = _model.getChild(node, i);
    if (childNode != peekNode) {
    TreePath treePath = temp
    .pathByAddingChild(childNode);
    if (_tree.isCheckBoxVisible(treePath)
    && _tree.isCheckBoxEnabled(treePath)) {
    toBeAdded.add(treePath);
    }
    }
    }
    }
    if (toBeAdded.size() > 0) {
    delegateAddSelectionPaths(toBeAdded
    .toArray(new TreePath[toBeAdded.size()]));
    }
    delegateRemoveSelectionPaths(new TreePath[] { parent });
    } finally {
    _fireEvent = true;
    if (isSingleEventMode() && fireEventAtTheEnd) {
    notifyPathChange(new TreePath[] { path }, false, path);
    }
    }
    }

    public boolean isSingleEventMode() {
    return _singleEventMode;
    }

    /**
    * Single event mode is a mode that always fires only one event when you select or unselect a tree node.
    * <p/>
    * Taking this tree as an example,
    * <p/>
    * <code><pre>
    * A -- a
    * ? |- b
    * ? |- c
    * </code></pre>
    * Case 1: Assuming b and c are selected at this point, you click on a.
    * <br>
    * <ul>
    * <li>In non-single event mode, you will get select-A, deselect-b and deselect-c three events
    * <li>In single event mode, you will only get select-a.
    * </ul>
    * <p/>
    * Case 2: Assuming none of the nodes are selected, you click on A. In this case, both modes result in the same behavior.
    * <ul>
    * <li>In non-single event mode, you will get only select-A event.
    * <li>In single event mode, you will only get select-A too.
    * </ul>
    * Case 3: Assuming b and c are selected and now you click on A.
    * <ul>
    * <li>In non-single event mode, you will get select-A event as well as deselect-b and deselect-c event.
    * <li>In single event mode, you will only get select-A.
    * </ul>
    * As you can see, single event mode will always fire the event on the nodes you select. However it doesn't reflect
    * what really happened inside the selection model. So if you want to get
    * a complete picture of the selection state inside selection model, you should use {@link #getSelectionPaths()} to find out.
    * In non-single event mode, the events reflect what happened inside the selection model. So you can get a complete picture
    * of the exact state without asking the selection model. The downside is it will generate too many events. With this option, you
    * can decide which mode you want to use that is the best for your case.
    * <p/>
    * By default, singleEventMode is set to false to be compatible with the older versions that don't have this option.
    *
    * @param singleEventMode true or false.
    */
    public void setSingleEventMode(boolean singleEventMode) {
    _singleEventMode = singleEventMode;
    }

    /**
    * Notifies listeners of a change in path. changePaths should contain
    * instances of PathPlaceHolder.
    *
    * @param changedPaths the paths that are changed.
    * @param isNew is it a new path.
    * @param oldLeadSelection the old selection.
    */
    protected void notifyPathChange(TreePath[] changedPaths,
    boolean isNew, TreePath oldLeadSelection) {
    int cPathCount = changedPaths.length;
    boolean[] newness = new boolean[cPathCount];

    for (int counter = 0; counter < cPathCount; counter++) {
    newness[counter] = isNew;
    }

    TreeSelectionEvent event = new TreeSelectionEvent(this ,
    changedPaths, newness, oldLeadSelection, leadPath);

    fireValueChanged(event);
    }

    // do not use it for now
    private boolean _batchMode = false;

    private boolean isBatchMode() {
    return _batchMode;
    }

    public void setBatchMode(boolean batchMode) {
    _batchMode = batchMode;
    if (!_batchMode) {
    super .addSelectionPaths(_toBeAdded
    .toArray(new TreePath[_toBeAdded.size()]));
    _toBeAdded.clear();
    super .removeSelectionPaths(_toBeRemoved
    .toArray(new TreePath[_toBeRemoved.size()]));
    _toBeRemoved.clear();
    }
    }

    private List<TreePath> _toBeAdded = new ArrayList();
    private List<TreePath> _toBeRemoved = new ArrayList();

    private void delegateRemoveSelectionPaths(TreePath[] paths) {
    if (!isBatchMode()) {
    super .removeSelectionPaths(paths);
    } else {
    for (TreePath path : paths) {
    _toBeRemoved.add(path);
    _toBeAdded.remove(path);
    }
    }
    }

    private void delegateRemoveSelectionPath(TreePath path) {
    if (!isBatchMode()) {
    super .removeSelectionPath(path);
    } else {
    _toBeRemoved.add(path);
    _toBeAdded.remove(path);
    }

    }

    private void delegateAddSelectionPaths(TreePath[] paths) {
    if (!isBatchMode()) {
    super .addSelectionPaths(paths);
    } else {
    for (TreePath path : paths) {
    _toBeAdded.add(path);
    _toBeRemoved.remove(path);
    }
    }
    }

    private void delegateAddSelectionPath(TreePath path) {
    if (!isBatchMode()) {
    super.addSelectionPath(path);
    } else {
    _toBeAdded.add(path);
    _toBeRemoved.remove(path);
    }
    }
    }

  11. #11
    shajuantony is offline Member
    Join Date
    Mar 2009
    Posts
    10
    Rep Power
    0

    Smile JCheckbox in JTree

    import javax.swing.*;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.text.Position;
    import javax.swing.tree.*;
    import java.awt.*;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.util.Hashtable;
    import java.util.Vector;


    public class CheckBoxTree extends JTree {

    public final static String PROPERTY_CHECKBOX_ENABLED = "checkBoxEnabled";
    public final static String PROPERTY_DIG_IN = "digIn";

    protected CheckBoxTreeCellRenderer _treeCellRenderer;

    private CheckBoxTreeSelectionModel _checkBoxTreeSelectionModel;

    private boolean _checkBoxEnabled = true;
    private PropertyChangeListener _modelChangeListener;

    public CheckBoxTree() {
    init();
    }

    public CheckBoxTree(Object[] value) {
    super (value);
    init();
    }

    public CheckBoxTree(Vector<?> value) {
    super (value);
    init();
    }

    public CheckBoxTree(Hashtable<?, ?> value) {
    super (value);
    init();
    }

    public CheckBoxTree(TreeNode root) {
    super (root);
    init();
    }

    public CheckBoxTree(TreeNode root, boolean asksAllowsChildren) {
    super (root, asksAllowsChildren);
    init();
    }

    public CheckBoxTree(TreeModel newModel) {
    super (newModel);
    init();
    }

    /**
    * Initialize the CheckBoxTree.
    */
    protected void init() {
    _checkBoxTreeSelectionModel = createCheckBoxTreeSelectionModel(getModel());
    _checkBoxTreeSelectionModel.setTree(this );
    Handler handler = createHandler();
    // JideSwingUtilities.insertMouseListener(this , handler, 0);
    addKeyListener(handler);
    _checkBoxTreeSelectionModel.addTreeSelectionListen er(handler);

    if (_modelChangeListener == null) {
    _modelChangeListener = new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {
    updateRowMapper();
    }
    };
    }
    addPropertyChangeListener(JTree.SELECTION_MODEL_PR OPERTY,
    _modelChangeListener);
    updateRowMapper();
    }

    /**
    * Creates the CheckBoxTreeSelectionModel.
    *
    * @param model the tree model.
    * @return the CheckBoxTreeSelectionModel.
    */
    protected CheckBoxTreeSelectionModel createCheckBoxTreeSelectionModel(
    TreeModel model) {
    return new CheckBoxTreeSelectionModel(model);
    }

    /**
    * RowMapper is necessary for contiguous selection.
    */
    private void updateRowMapper() {
    _checkBoxTreeSelectionModel.setRowMapper(getSelect ionModel()
    .getRowMapper());
    }

    @Override
    public void setModel(TreeModel newModel) {
    super .setModel(newModel);
    if (_checkBoxTreeSelectionModel != null) {
    _checkBoxTreeSelectionModel.setModel(getModel());
    }
    }

    /**
    * Gets the cell renderer with check box.
    *
    * @return CheckBoxTree's own cell renderer which has the check box. The actual cell renderer
    * you set by setCellRenderer() can be accessed by using {@link #getActualCellRenderer()}.
    */
    @Override
    public TreeCellRenderer getCellRenderer() {
    TreeCellRenderer cellRenderer = super .getCellRenderer();
    if (cellRenderer == null) {
    cellRenderer = new DefaultTreeCellRenderer();
    }
    if (_treeCellRenderer == null) {
    _treeCellRenderer = createCellRenderer(cellRenderer);
    } else {
    _treeCellRenderer.setActualTreeRenderer(cellRender er);
    }
    return _treeCellRenderer;
    }

    /**
    * Gets the actual cell renderer. Since CheckBoxTree has its own check box cell renderer, this method
    * will give you access to the actual cell renderer which is either the default tree cell renderer or
    * the cell renderer you set using {@link #setCellRenderer(javax.swing.tree.TreeCellRenderer )}.
    *
    * @return the actual cell renderer
    */
    public TreeCellRenderer getActualCellRenderer() {
    if (_treeCellRenderer != null) {
    return _treeCellRenderer.getActualTreeRenderer();
    } else {
    return super .getCellRenderer();
    }
    }

    /**
    * Creates the cell renderer.
    *
    * @param renderer the actual renderer for the tree node. This method will
    * return a cell renderer that use a check box and put the actual renderer inside it.
    * @return the cell renderer.
    */
    protected CheckBoxTreeCellRenderer createCellRenderer(
    TreeCellRenderer renderer) {
    final CheckBoxTreeCellRenderer checkBoxTreeCellRenderer = new CheckBoxTreeCellRenderer(
    renderer);
    addPropertyChangeListener(CELL_RENDERER_PROPERTY,
    new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {
    checkBoxTreeCellRenderer
    .setActualTreeRenderer((TreeCellRenderer) evt
    .getNewValue());
    }
    });
    return checkBoxTreeCellRenderer;
    }

    /**
    * Creates the mouse listener and key listener used by CheckBoxTree.
    *
    * @return the Handler.
    */
    protected Handler createHandler() {
    return new Handler(this );
    }

    protected static class Handler implements MouseListener,
    KeyListener, TreeSelectionListener {
    protected CheckBoxTree _tree;
    int _hotspot = new JCheckBox().getPreferredSize().width;
    private int _toggleCount = -1;

    public Handler(CheckBoxTree tree) {
    _tree = tree;
    }

    protected TreePath getTreePathForMouseEvent(MouseEvent e) {
    if (!SwingUtilities.isLeftMouseButton(e)) {
    return null;
    }

    if (!_tree.isCheckBoxEnabled()) {
    return null;
    }

    TreePath path = _tree
    .getPathForLocation(e.getX(), e.getY());
    if (path == null)
    return null;

    if (clicksInCheckBox(e, path)) {
    return path;
    } else {
    return null;
    }
    }

    protected boolean clicksInCheckBox(MouseEvent e, TreePath path) {
    if (!_tree.isCheckBoxVisible(path)) {
    return false;
    } else {
    Rectangle bounds = _tree.getPathBounds(path);
    if (_tree.getComponentOrientation().isLeftToRight()) {
    return e.getX() < bounds.x + _hotspot;
    } else {
    return e.getX() > bounds.x + bounds.width
    - _hotspot;
    }
    }
    }

    private TreePath preventToggleEvent(MouseEvent e) {
    TreePath pathForMouseEvent = getTreePathForMouseEvent(e);
    if (pathForMouseEvent != null) {
    int toggleCount = _tree.getToggleClickCount();
    if (toggleCount != -1) {
    _toggleCount = toggleCount;
    _tree.setToggleClickCount(-1);
    }
    }
    return pathForMouseEvent;
    }

    public void mouseClicked(MouseEvent e) {
    preventToggleEvent(e);
    }

    public void mousePressed(MouseEvent e) {
    TreePath path = preventToggleEvent(e);
    if (path != null) {
    toggleSelection(path);
    e.consume();
    }
    }

    public void mouseReleased(MouseEvent e) {
    TreePath path = preventToggleEvent(e);
    if (path != null) {
    e.consume();
    }
    if (_toggleCount != -1) {
    _tree.setToggleClickCount(_toggleCount);
    }
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void keyPressed(KeyEvent e) {
    if (e.isConsumed()) {
    return;
    }

    if (!_tree.isCheckBoxEnabled()) {
    return;
    }

    if (e.getModifiers() == 0
    && e.getKeyChar() == KeyEvent.VK_SPACE)
    toggleSelections();
    }

    public void keyTyped(KeyEvent e) {
    }

    public void keyReleased(KeyEvent e) {
    }

    public void valueChanged(TreeSelectionEvent e) {
    _tree.treeDidChange();
    }

    private void toggleSelection(TreePath path) {
    if (!_tree.isEnabled() || !_tree.isCheckBoxEnabled(path)) {
    return;
    }
    CheckBoxTreeSelectionModel selectionModel = _tree
    .getCheckBoxTreeSelectionModel();
    boolean selected = selectionModel.isPathSelected(path,
    selectionModel.isDigIn());
    selectionModel.removeTreeSelectionListener(this );
    try {
    if (!selectionModel.isSingleEventMode()) {
    selectionModel.setBatchMode(true);
    }
    if (selected)
    selectionModel.removeSelectionPath(path);
    else
    selectionModel.addSelectionPath(path);
    } finally {
    if (!selectionModel.isSingleEventMode()) {
    selectionModel.setBatchMode(false);
    }
    selectionModel.addTreeSelectionListener(this );
    _tree.treeDidChange();
    }
    }

    protected void toggleSelections() {
    TreePath[] treePaths = _tree.getSelectionPaths();
    if (treePaths == null) {
    return;
    }
    for (TreePath treePath : treePaths) {
    toggleSelection(treePath);
    }
    }
    }

    @Override
    public TreePath getNextMatch(String prefix, int startingRow,
    Position.Bias bias) {
    return null;
    }

    /**
    * Gets the selection model for the check boxes. To retrieve the state of check boxes, you should use this selection model.
    *
    * @return the selection model for the check boxes.
    */
    public CheckBoxTreeSelectionModel getCheckBoxTreeSelectionModel() {
    return _checkBoxTreeSelectionModel;
    }

    /**
    * Gets the value of property checkBoxEnabled. If true, user can
    * click on check boxes on each tree node to select and unselect.
    * If false, user can't click but you as developer can programatically
    * call API to select/unselect it.
    *
    * @return the value of property checkBoxEnabled.
    */
    public boolean isCheckBoxEnabled() {
    return _checkBoxEnabled;
    }

    /**
    * Sets the value of property checkBoxEnabled.
    *
    * @param checkBoxEnabled true to allow to check the check box. False to disable it
    * which means user can see whether a row is checked or not but they cannot change it.
    */
    public void setCheckBoxEnabled(boolean checkBoxEnabled) {
    if (checkBoxEnabled != _checkBoxEnabled) {
    Boolean oldValue = _checkBoxEnabled ? Boolean.TRUE
    : Boolean.FALSE;
    Boolean newValue = checkBoxEnabled ? Boolean.TRUE
    : Boolean.FALSE;
    _checkBoxEnabled = checkBoxEnabled;
    firePropertyChange(PROPERTY_CHECKBOX_ENABLED, oldValue,
    newValue);
    repaint();
    }
    }

    /**
    * Checks if check box is enabled. There is no setter for it. The only way is to override
    * this method to return true or false.
    *
    * @param path the tree path.
    * @return true or false. If false, the check box on the particular tree path will be disabled.
    */
    public boolean isCheckBoxEnabled(TreePath path) {
    return true;
    }

    /**
    * Checks if check box is visible. There is no setter for it. The only way is to override
    * this method to return true or false.
    *
    * @param path the tree path.
    * @return true or false. If false, the check box on the particular tree path will be disabled.
    */
    public boolean isCheckBoxVisible(TreePath path) {
    return true;
    }

    /**
    * Gets the dig-in mode. If the CheckBoxTree is in dig-in mode, checking the parent node
    * will check all the children. Correspondingly, getSelectionPaths() will only return the
    * parent tree path. If not in dig-in mode, each tree node can be checked or unchecked independently
    *
    * @return true or false.
    */
    public boolean isDigIn() {
    return getCheckBoxTreeSelectionModel().isDigIn();
    }

    /**
    * Sets the dig-in mode. If the CheckBoxTree is in dig-in mode, checking the parent node
    * will check all the children. Correspondingly, getSelectionPaths() will only return the
    * parent tree path. If not in dig-in mode, each tree node can be checked or unchecked independently
    *
    * @param digIn the new digIn mode.
    */
    public void setDigIn(boolean digIn) {
    boolean old = isDigIn();
    if (old != digIn) {
    getCheckBoxTreeSelectionModel().setDigIn(digIn);
    firePropertyChange(PROPERTY_DIG_IN, old, digIn);
    }
    }


    }

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. How to add JCheckbox as a node in JTree
    By shajuantony in forum New To Java
    Replies: 0
    Last Post: 04-09-2009, 08:19 AM
  3. JCheckBox in JTable column
    By hind in forum New To Java
    Replies: 8
    Last Post: 01-04-2009, 08:40 PM
  4. Regarding JTree with JCheckBox and JRadioButton
    By partha_adt in forum AWT / Swing
    Replies: 0
    Last Post: 11-11-2008, 11:03 AM
  5. jcheckbox issues need help. thanks.
    By carlos123 in forum New To Java
    Replies: 3
    Last Post: 11-05-2007, 11:37 PM

Posting Permissions

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