快速业务通道

SWING?1ê??μí3???tê÷ - ±à3ìè???í?

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-15

SWING?1ê??μí3???tê÷

ê±??:2011-08-11 ?ˉ?ò??3±

ò?°??é????£?11?¨ò??? SWING ê÷£???ê??èòa11?¨o?′?·?êy?Yμ??£Dí (TreeModel), ?úò?°??é????£?êμ ???eà′????óD?êìa£?μ?μ±êy?Yá?·?3£′óμ?ê±oò£?ò?′?D?11?¨o? TreeModel £????á?¨·?oü?àê±??£?????′| óú?òμ?μ?×′ì?£¨μ±è??éò?áí?a??????3ì£??éò?2ù×÷????????£?£??a????ó??§μ??D??·?3£2??£?a???a???êìa μ?1??ü?úóú£?ê÷?£Díμ?êy?Y?£?ò?????aμà£??μí3???tê?ò?2?ò?2?oüóD2?′?D?£??a?ù?ò???í?éò?ò?ò??????t £¨2?1üê????t?1ê????t?D£??aê÷?úμ?£?μ±3?′??ó??ê÷μ?ê±oò£?μ??÷ê÷?úμ?£??è?D????óD??óD×ó?úμ?£?è??T £??íè¥?áè¥???úμ?μ?±£′?μ????tD??¢£?è??a???t?D£??íè¥è??????t?D??μ??ùóD???t£?11?ì3?ê÷?úμ?£??óμ? ê÷?D?£μú?t′?μ??÷μ?ê±oò£??í2??áè¥?á′??ì???t?μí3á??£

′ú????μ¥£o

import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import java.io.*; import java.awt.*; import javax.swing.*; import javax.swing.tree.TreeCellRenderer; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.tree.TreePath; /** * <p>Title: JDHSystemFileTree</p> * <p>Description: ?μí3????ê÷£??ˉì?éú3é£??a????è??yμ??êìa </p> * <p>Copyright: Copyright (c) 2007</p> * @author ?ˉ?ò??3± * @version 1.0 */ public class SystemFileTree { ???? private DefaultTreeModel model; ???? private JTree tree; ???? public SystemFileTree () { ???????? JFrame f=new JFrame(); ???????? f.getContentPane().setLayout(new BorderLayout()); ???????? tree=new JTree(); ?????? tree.addMouseListener(new MouseAdapter(){ ???????????? public void mousePressed(MouseEvent e){ ???????????????? node_mouseAction(e); ???????????? } ???????? }); ???????? JScrollPane scroll=new JScrollPane(tree); ???????? f.getContentPane().add(scroll,BorderLayout.CENTER); ???????? f.setLocation(250,250); ???????? f.setSize(new Dimension(300,500)); ???????? f.setVisible(true); ???? } ???? private void node_mouseAction(MouseEvent e){ ???????? int row = tree.getRowForLocation(e.getX(), e.getY()); ???????? PathNode pathNode =null; ???????? if(row != -1){ ???????? TreePath path = tree.getPathForRow(row); ???????? pathNode = (PathNode)path.getLastPathComponent(); ???????? if(pathNode.isFolder()&&pathNode.getChildCount()==0){ ???????????? builderNode(pathNode); ???????????? tree.expandPath(path); ???????? } ???????? } ???? } ???? private PathNode builderNode(PathNode pathNode){ ???????? String filePath= pathNode.getValue().toString(); ???????? File file=new File(filePath); ???????? File[] files=file.listFiles(); ?????? for(int i=0;i<files.length;i++){ ?????????? PathNode node=new PathNode(files[i].getName(), files[i].getAbsolutePath (),files[i].isDirectory()); ?????????? pathNode.add(node); ?????? } ???????? return pathNode; ???? } ???? private void initData(String??rootPath){ ???????? Fil

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号