package course;

import java.awt.BorderLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 * JScrollPane优化示例
 * @author SongFei
 * @date 2015年5月17日
 */
public class Demo2 extends JFrame {

	private JPanel content;
	private JTree tree;
	private JScrollPane scrollPane;

	public Demo2() {
		setSize(300, 400);
		setTitle("course");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		tree = new JTree(getRootNode());
		
		content = new JPanel();
		content.setLayout(new BorderLayout());
		
		scrollPane = new JScrollPane();
		scrollPane.setViewportView(tree);
		scrollPane.getVerticalScrollBar().setUI(new DemoScrollBarUI());
		content.add(scrollPane, BorderLayout.CENTER);
		
		getContentPane().add(content);
	}

	/**
	 * 创建root节点
	 * @return
	 */
	private DefaultMutableTreeNode getRootNode() {
		DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
		root.add(new DefaultMutableTreeNode("node1"));
		root.add(new DefaultMutableTreeNode("node2"));
		root.add(new DefaultMutableTreeNode("node3"));
		root.add(new DefaultMutableTreeNode("node4"));
		root.add(new DefaultMutableTreeNode("node5"));
		root.add(new DefaultMutableTreeNode("node6"));
		root.add(new DefaultMutableTreeNode("node7"));
		root.add(new DefaultMutableTreeNode("node8"));
		root.add(new DefaultMutableTreeNode("node9"));
		root.add(new DefaultMutableTreeNode("node10"));
		root.add(new DefaultMutableTreeNode("node11"));
		root.add(new DefaultMutableTreeNode("node12"));
		root.add(new DefaultMutableTreeNode("node13"));
		root.add(new DefaultMutableTreeNode("node14"));
		root.add(new DefaultMutableTreeNode("node15"));
		root.add(new DefaultMutableTreeNode("node16"));
		root.add(new DefaultMutableTreeNode("node17"));
		root.add(new DefaultMutableTreeNode("node18"));
		root.add(new DefaultMutableTreeNode("node19"));
		root.add(new DefaultMutableTreeNode("node20"));
		return root;
	}
	
	public static void main(String[] args) {
		Demo2 demo1 = new Demo2();
		demo1.setVisible(true);
		demo1.setLocationRelativeTo(null);
	}

}
最近下载更多
yeyuantao  LV6 2023年3月1日
banliyoo  LV2 2021年9月15日
huochai666  LV3 2021年6月18日
22395797  LV3 2021年1月18日
xcj456  LV8 2020年9月12日
上善_若水  LV3 2020年3月13日
最代码吴  LV2 2020年1月8日
hyw789  LV5 2019年11月6日
applex  LV1 2019年6月7日
嗯嗯恩呢嫩嗯呢  LV1 2019年4月6日
最近浏览更多
woldxy  LV12 4月1日
dsuccess 2023年7月5日
暂无贡献等级
漫步的海星  LV4 2023年3月24日
yeyuantao  LV6 2023年3月1日
ruifeng  LV4 2022年7月22日
jacktingxiao 2022年3月31日
暂无贡献等级
nmd2022 2022年3月20日
暂无贡献等级
1415545830qq 2022年3月11日
暂无贡献等级
微信网友_5852742079762432  LV6 2022年2月28日
调戏红颜 2022年1月18日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友