资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

javaJTreeJCheckBox树复选框详解-创新互联

本文实例为大家分享了java JTree JCheckBox树复选框展示的具体代码,供大家参考,具体内容如下

成都创新互联专注于网站建设,为客户提供网站制作、成都网站设计、网页设计开发服务,多年建网站服务经验,各类网站都可以开发,品牌网站制作,公司官网,公司展示网站,网站设计,建网站费用,建网站多少钱,价格优惠,收费合理。

1.CheckTreeManager.java


public class CheckTreeManager extends MouseAdapter implements TreeSelectionListener 
{ 
 
  private CheckTreeSelectionModel selectionModel = null; 
  
// private JTree tree = new JTree(); 
  private JTree tree = null; 
  
  int hotspot = new JCheckBox().getPreferredSize().width; 
  
  public CheckTreeManager(JTree tree) 
  { 
   this.tree = tree; 
   selectionModel = new CheckTreeSelectionModel(tree.getModel()); 
   tree.setCellRenderer(new CheckTreeCellRenderer(tree.getCellRenderer(), selectionModel)); 
   tree.addMouseListener(this); //鼠标监听 
   selectionModel.addTreeSelectionListener(this); //树选择监听 
  } 
  
  public void mouseClicked(MouseEvent me) 
  { 
   TreePath path = tree.getPathForLocation(me.getX(), me.getY()); 
   if(path==null) 
    return; 
   if(me.getX()>tree.getPathBounds(path).x+hotspot) 
    return; 
   
   boolean selected = selectionModel.isPathSelected(path, true); 
   selectionModel.removeTreeSelectionListener(this); 
   
   try 
   { 
    if(selected) 
     selectionModel.removeSelectionPath(path); 
    else 
     selectionModel.addSelectionPath(path); 
   } 
   finally 
   { 
    selectionModel.addTreeSelectionListener(this); 
    tree.treeDidChange(); 
   } 
  } 
  
  public CheckTreeSelectionModel getSelectionModel() 
  { 
   return selectionModel; 
  } 
  
  public void valueChanged(TreeSelectionEvent e) 
  { 
   tree.treeDidChange(); 
  } 
  
} 

本文标题:javaJTreeJCheckBox树复选框详解-创新互联
分享URL:http://cdkjz.cn/article/djojop.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220