JTree树形结构

论坛 期权论坛 脚本     
匿名技术用户   2020-12-29 14:38   11   0

//Tree.java
//树形结构
//2009-11-3
//<applet code=Tree width=200 height=100>
//</applet>

import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;

public class Tree extends JApplet
{
public void init(){
DefaultMutableTreeNode root=new DefaultMutableTreeNode("JTree");
DefaultMutableTreeNode colors=new DefaultMutableTreeNode("Color");
DefaultMutableTreeNode style=new DefaultMutableTreeNode("style");
DefaultMutableTreeNode sports=new DefaultMutableTreeNode("sports");
root.add(colors);
root.add(style);
root.add(sports);

DefaultMutableTreeNode red=new DefaultMutableTreeNode("Red");
DefaultMutableTreeNode blue=new DefaultMutableTreeNode("blue");
DefaultMutableTreeNode white=new DefaultMutableTreeNode("white");
colors.add(red);
colors.add(blue);
colors.add(white);

DefaultMutableTreeNode liNing=new DefaultMutableTreeNode("LiNING");
DefaultMutableTreeNode nike=new DefaultMutableTreeNode("Nike");
sports.add(liNing);
sports.add(nike);

JTree tree=new JTree(root);

Container cp=getContentPane();
cp.setLayout(new FlowLayout());
cp.add(tree);
}
}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP