JAVA JBuilder 2006里面 JTree 节点怎么加图片,说详细点我是新手
可以再以下代码中示范么还是要自己写方法DefaultMutableTreeNoderoot=newDefaultMutableTreeNode("资产查询");//Def...
可以再以下代码中示范么 还是要自己写方法
DefaultMutableTreeNode root = new DefaultMutableTreeNode("资产查询");
// DefaultMutableTreeNode parent1 = new DefaultMutableTreeNode("办公外设");
// DefaultMutableTreeNode parent2 = new DefaultMutableTreeNode("数码产品");
// DefaultMutableTreeNode parent3 = new DefaultMutableTreeNode("计算机");
// DefaultMutableTreeNode leafa = new DefaultMutableTreeNode("传真机");
// DefaultMutableTreeNode leafa1 = new DefaultMutableTreeNode("复印机");
// DefaultMutableTreeNode leafa2 = new DefaultMutableTreeNode("打印机");
// DefaultMutableTreeNode leafb = new DefaultMutableTreeNode("数码相机");
// DefaultMutableTreeNode leafb1 = new DefaultMutableTreeNode("投影机");
// DefaultMutableTreeNode leafc = new DefaultMutableTreeNode("笔记本电脑");
// DefaultMutableTreeNode leafc1 = new DefaultMutableTreeNode("台式机");
// DefaultMutableTreeNode leafc2 = new DefaultMutableTreeNode("服务器");
// parent1.add(leafa);
// parent1.add(leafa1);
// parent1.add(leafa2);
// parent2.add(leafb);
// parent2.add(leafb1);
// parent3.add(leafc);
// parent3.add(leafa1);
// parent3.add(leafa2);
// root.add(parent1);
// root.add(parent2);
// root.add(parent3);
// this.jTree1 = new JTree(root);
我还是不行啊 弄不出来啊谁再帮帮忙啊 展开
DefaultMutableTreeNode root = new DefaultMutableTreeNode("资产查询");
// DefaultMutableTreeNode parent1 = new DefaultMutableTreeNode("办公外设");
// DefaultMutableTreeNode parent2 = new DefaultMutableTreeNode("数码产品");
// DefaultMutableTreeNode parent3 = new DefaultMutableTreeNode("计算机");
// DefaultMutableTreeNode leafa = new DefaultMutableTreeNode("传真机");
// DefaultMutableTreeNode leafa1 = new DefaultMutableTreeNode("复印机");
// DefaultMutableTreeNode leafa2 = new DefaultMutableTreeNode("打印机");
// DefaultMutableTreeNode leafb = new DefaultMutableTreeNode("数码相机");
// DefaultMutableTreeNode leafb1 = new DefaultMutableTreeNode("投影机");
// DefaultMutableTreeNode leafc = new DefaultMutableTreeNode("笔记本电脑");
// DefaultMutableTreeNode leafc1 = new DefaultMutableTreeNode("台式机");
// DefaultMutableTreeNode leafc2 = new DefaultMutableTreeNode("服务器");
// parent1.add(leafa);
// parent1.add(leafa1);
// parent1.add(leafa2);
// parent2.add(leafb);
// parent2.add(leafb1);
// parent3.add(leafc);
// parent3.add(leafa1);
// parent3.add(leafa2);
// root.add(parent1);
// root.add(parent2);
// root.add(parent3);
// this.jTree1 = new JTree(root);
我还是不行啊 弄不出来啊谁再帮帮忙啊 展开
1个回答
展开全部
先定义5个图标如下:
//句柄展开时的图标
Icon ExpandedIcon=new ImageIcon("图标文件路径");
//句柄折叠时的图标
Icon CollapsedIcon=new ImageIcon("图标文件路径");
//叶节点的图标,也就是下面没有子结点的节点图标
Icon LeafIcon=new ImageIcon("图标文件路径");
//非叶节点关闭时的图标,也就是下面有子结点的节点图标
Icon ClosedIcon=new ImageIcon("图标文件路径");
//非叶节点打开时的图标
DefaultTreeCellRenderer render=(DefaultTreeCellRenderer)(jTree1.getCellRenderer());
render.setLeafIcon(LeafIcon);
render.setClosedIcon(ClosedIcon);
render.setOpenIcon(OpenedIcon);
BasicTreeUI ui=(BasicTreeUI)(jTree1.getUI());
ui.setCollapsedIcon(CollapsedIcon);
ui.setExpandedIcon(ExpandedIcon);
Icon OpenedIcon=new ImageIcon("image/Opened.gif");
把以上代码追加到你代码的后面就可以了
//句柄展开时的图标
Icon ExpandedIcon=new ImageIcon("图标文件路径");
//句柄折叠时的图标
Icon CollapsedIcon=new ImageIcon("图标文件路径");
//叶节点的图标,也就是下面没有子结点的节点图标
Icon LeafIcon=new ImageIcon("图标文件路径");
//非叶节点关闭时的图标,也就是下面有子结点的节点图标
Icon ClosedIcon=new ImageIcon("图标文件路径");
//非叶节点打开时的图标
DefaultTreeCellRenderer render=(DefaultTreeCellRenderer)(jTree1.getCellRenderer());
render.setLeafIcon(LeafIcon);
render.setClosedIcon(ClosedIcon);
render.setOpenIcon(OpenedIcon);
BasicTreeUI ui=(BasicTreeUI)(jTree1.getUI());
ui.setCollapsedIcon(CollapsedIcon);
ui.setExpandedIcon(ExpandedIcon);
Icon OpenedIcon=new ImageIcon("image/Opened.gif");
把以上代码追加到你代码的后面就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询