ssh终端界面(编码中)-MenuTree

package com.cod.ui.terminal;

import java.awt.Color;
import java.awt.Font;

import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;

public class MenuTree extends JTree {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2592143182163404677L;

	public MenuTree() {
		super(getTreeModel());
		setRowHeight(20);
		// 设置成Alloy界面样式

		try {
			// 设置样式
			// UIManager
			// .setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
			// .setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");// Metal风格 (默认)
			// .setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");//
			// Windows风格
			// .setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");//
			// Windows Classic风格
			// .setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");// Motif风格
			// .setLookAndFeel("com.sun.java.swing.plaf.mac.MacLookAndFeel");// Mac风格
			// (需要在相关的操作系统上方可实现)
			// .setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");// GTK风格
			// (需要在相关的操作系统上方可实现)
			// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());//
			// 可跨平台的默认风格
			String lookAndFeel = UIManager.getSystemLookAndFeelClassName();
			UIManager.setLookAndFeel(lookAndFeel);// 当前系统的风格
		} catch (Throwable e) {

			e.printStackTrace();
		}

		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
				| UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		SwingUtilities.updateComponentTreeUI(this);
		/*
		 DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) this
		 .getCellRenderer(); cellRenderer.setLeafIcon(new
		 ImageIcon("..\\icons\\leaf.gif")); cellRenderer.setOpenIcon(new
		 ImageIcon("..\\icons\\open.gif")); cellRenderer.setClosedIcon(new
		 ImageIcon("..\\icons\\close.gif"));
		 
		 cellRenderer.setFont(new Font("宋体", Font.PLAIN, 12));// 设置字体.
		 cellRenderer.setBackgroundNonSelectionColor(Color.white);
		 cellRenderer.setBackgroundSelectionColor(Color.yellow);
		 cellRenderer.setBorderSelectionColor(Color.red);
		 
		 设置选时或不选时,文字的变化颜色
		 
		 cellRenderer.setTextNonSelectionColor(Color.black);
		 cellRenderer.setTextSelectionColor(Color.blue);
		 */

	}

	public static DefaultTreeModel getTreeModel() {
		DefaultMutableTreeNode root = new DefaultMutableTreeNode("主目录");
		DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("会话管理");
		DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("常用功能");
		DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("全局设置");
		DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("关于");

		DefaultTreeModel treeModel = new DefaultTreeModel(root);
		treeModel.insertNodeInto(node1, root, root.getChildCount());
		treeModel.insertNodeInto(node2, root, root.getChildCount());
		treeModel.insertNodeInto(node3, root, root.getChildCount());
		treeModel.insertNodeInto(node4, root, root.getChildCount());

		DefaultMutableTreeNode leafnode = new DefaultMutableTreeNode("118");
		treeModel.insertNodeInto(leafnode, node1, node1.getChildCount());
		leafnode = new DefaultMutableTreeNode("177");
		treeModel.insertNodeInto(leafnode, node1, node1.getChildCount());
		leafnode = new DefaultMutableTreeNode("24");
		treeModel.insertNodeInto(leafnode, node1, node1.getChildCount());

		leafnode = new DefaultMutableTreeNode("最近会话");
		treeModel.insertNodeInto(leafnode, node2, node2.getChildCount());
		leafnode = new DefaultMutableTreeNode("常用命令");
		treeModel.insertNodeInto(leafnode, node2, node2.getChildCount());
		leafnode = new DefaultMutableTreeNode("常用脚本");
		treeModel.insertNodeInto(leafnode, node2, node2.getChildCount());

		DefaultMutableTreeNode node31 = new DefaultMutableTreeNode("全局设置");
		treeModel.insertNodeInto(node31, node3, node3.getChildCount());
		leafnode = new DefaultMutableTreeNode("连接");
		treeModel.insertNodeInto(leafnode, node3, node3.getChildCount());
		leafnode = new DefaultMutableTreeNode("编码");
		treeModel.insertNodeInto(leafnode, node3, node3.getChildCount());
		leafnode = new DefaultMutableTreeNode("主题");
		treeModel.insertNodeInto(leafnode, node3, node3.getChildCount());
		return treeModel;
	}

}

 

你可能感兴趣的:(ssh终端界面(编码中)-MenuTree)