java代码生成树形菜单,java实现树菜单
java,jsp带checkbox的树形菜单,如何实现?
jsp中带有checkbox的属性菜单需要用easyui组件来实现,代码如下:
为衡水等地区用户提供了全套网页设计制作服务,及衡水网站建设行业解决方案。主营业务为成都网站建设、成都网站设计、衡水网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
!DOCTYPE html
html
head
meta charset="UTF-8"
titleCheckBox Tree - jQuery EasyUI Demo/title
link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css"
link rel="stylesheet" type="text/css" href="../../themes/icon.css"
link rel="stylesheet" type="text/css" href="../demo.css"
script type="text/javascript" src="../../jquery.min.js"/script
script type="text/javascript" src="../../jquery.easyui.min.js"/script
/head
body
h2CheckBox Tree/h2
pTree nodes with check boxes./p
div style="margin:20px 0;"
a href="#" class="easyui-linkbutton" onclick="getChecked()"GetChecked/a
/div
div style="margin:10px 0"
input type="checkbox" checked onchange="$('#tt').tree({cascadeCheck:$(this).is(':checked')})"CascadeCheck
input type="checkbox" onchange="$('#tt').tree({onlyLeafCheck:$(this).is(':checked')})"OnlyLeafCheck
/div
div class="easyui-panel" style="padding:5px"
ul id="tt" class="easyui-tree" data-options="url:'tree_data1.json',method:'get',animate:true,checkbox:true"/ul
/div
script type="text/javascript"
function getChecked(){
var nodes = $('#tt').tree('getChecked');
var s = '';
for(var i=0; inodes.length; i++){
if (s != '') s += ',';
s += nodes[i].text;
}
alert(s);
}
/script
/body
/html
运行效果:
java web树形菜单开发,求web高手~~
呵呵,你可以看一下easyUI框架的功能。
如果非要自己写的话:大体就是这样的:
ul
li id="ts"图书
ul id="tsts"li id="kx"科学类/lili id="wx"文学类/li/ul
/li
li id="yx"影像/li
/ul
其他的自己嵌套进去就可以了;
然后主要是在js里的处理:
$(functoin(){
var tsts = 0;
$("#tx").click(functon(){
if(tsts==0){
//this.child.display=none;具体设置属性的方法你看一下是不是这样的。
$("#tsts").css("display":"none");
tsts = 1;
} else{
$("#tsts").css("display":"block");
tsts = 0;
}
});
});
好吧,结构大体就是这样的了。还有那个加减号的变化你自己看一下。也要绑定的单击事件里面。
用java 生成一个树形菜单
package com.csii;
import java.awt.GridLayout;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
public class TreeDemo1 extends JFrame implements TreeSelectionListener {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTree jTree = null;
private JEditorPane jEditorPane = null;
private JScrollPane jScrollPane = null;
public JScrollPane getjScrollPane() {
if(jScrollPane==null){
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTree());
}
return jScrollPane;
}
DefaultMutableTreeNode top = null; // @jve:decl-index=0:
/**
* This is the default constructor
*/
public TreeDemo1() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(438, 309);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
gridLayout.setColumns(2);
jContentPane = new JPanel();
jContentPane.setLayout(gridLayout);
jContentPane.add(getjScrollPane(), null);
jContentPane.add(getJEditorPane(), null);
}
return jContentPane;
}
/**
* This method initializes jTree
*
* @return javax.swing.JTree
*/
private JTree getJTree() {
if (jTree == null) {
top = new DefaultMutableTreeNode("黄山");
createNodes(top);
jTree = new JTree(top);
jTree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
jTree.addTreeSelectionListener(this);
}
return jTree;
}
private void createNodes(DefaultMutableTreeNode top) {
DefaultMutableTreeNode jingdian = null, jiaotong = null, zhusu = null, binguan = null, luying = null, jiesu = null;
jingdian = new DefaultMutableTreeNode("景点");
jingdian.add(new DefaultMutableTreeNode("景点1"));
jingdian.add(new DefaultMutableTreeNode("景点2"));
jiaotong = new DefaultMutableTreeNode("交通");
jiaotong.add(new DefaultMutableTreeNode("路线1"));
jiaotong.add(new DefaultMutableTreeNode("路线2"));
jiaotong.add(new DefaultMutableTreeNode("路线3"));
zhusu = new DefaultMutableTreeNode("住宿");
zhusu.add(new DefaultMutableTreeNode("A住宿"));
zhusu.add(new DefaultMutableTreeNode("B住宿"));
zhusu.add(new DefaultMutableTreeNode("C住宿"));
binguan = new DefaultMutableTreeNode("宾馆");
binguan.add(new DefaultMutableTreeNode("X宾馆"));
binguan.add(new DefaultMutableTreeNode("Y宾馆"));
binguan.add(new DefaultMutableTreeNode("Z宾馆"));
binguan.add(new DefaultMutableTreeNode("XYZ宾馆"));
luying = new DefaultMutableTreeNode("露营");
luying.add(new DefaultMutableTreeNode("方式1"));
luying.add(new DefaultMutableTreeNode("方式2"));
jiesu = new DefaultMutableTreeNode("借宿");
jiesu.add(new DefaultMutableTreeNode("借宿1"));
jiesu.add(new DefaultMutableTreeNode("借宿2"));
jiesu.add(new DefaultMutableTreeNode("借宿3"));
top.add(jingdian);
top.add(jiaotong);
top.add(zhusu);
top.add(binguan);
top.add(luying);
top.add(jiesu);
}
/**
* This method initializes jEditorPane
*
* @return javax.swing.JEditorPane
*/
private JEditorPane getJEditorPane() {
if (jEditorPane == null) {
jEditorPane = new JEditorPane();
}
return jEditorPane;
}
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree
.getLastSelectedPathComponent();
if (node == null)
// Nothing is selected.
return;
if(node.isRoot()){
jEditorPane.setText("黄山的简介");
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){
e.printStackTrace();
}
new TreeDemo1().setVisible(true);
}
});
}
}
java 如何生成三级树形菜单?
是要返回一个json串吧。mybytis里设置好要返回自定义的结果集合。就直接可以
java树形菜单编辑保存
在图形界面中添加文本框架实现文本编辑,通过鼠标菜单栏添加事件监听实现保存。
在开发中我们经常会遇到左边是树形菜单,右边是一个显示列表,单击左边的树形菜单项时,右边会显示该菜单里面相对应的内容。在实战开发中经常有需要处理树形菜单、树形目录等等等业务需求。
而对于这种产品,在设计数据库时也建议使用idparentId的结构来做。
如何用Java实现树形结构啊?
package tree;
import java.util.LinkedList;
import java.util.List;
/**
* 功能:把一个数组的值存入二叉树中,然后进行3种方式的遍历
*
* 参考资料0:数据结构(C语言版)严蔚敏
*
* 参考资料1:
*
* 参考资料2:
*
* @author ocaicai@yeah.net @date: 2011-5-17
*
*/
public class BinTreeTraverse2 {
private int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
private static ListNode nodeList = null;
/**
* 内部类:节点
*
* @author ocaicai@yeah.net @date: 2011-5-17
*
*/
private static class Node {
Node leftChild;
Node rightChild;
int data;
Node(int newData) {
leftChild = null;
rightChild = null;
data = newData;
}
}
public void createBinTree() {
nodeList = new LinkedListNode();
// 将一个数组的值依次转换为Node节点
for (int nodeIndex = 0; nodeIndex array.length; nodeIndex++) {
nodeList.add(new Node(array[nodeIndex]));
}
// 对前lastParentIndex-1个父节点按照父节点与孩子节点的数字关系建立二叉树
for (int parentIndex = 0; parentIndex array.length / 2 - 1; parentIndex++) {
// 左孩子
nodeList.get(parentIndex).leftChild = nodeList
.get(parentIndex * 2 + 1);
// 右孩子
nodeList.get(parentIndex).rightChild = nodeList
.get(parentIndex * 2 + 2);
}
// 最后一个父节点:因为最后一个父节点可能没有右孩子,所以单独拿出来处理
int lastParentIndex = array.length / 2 - 1;
// 左孩子
nodeList.get(lastParentIndex).leftChild = nodeList
.get(lastParentIndex * 2 + 1);
// 右孩子,如果数组的长度为奇数才建立右孩子
if (array.length % 2 == 1) {
nodeList.get(lastParentIndex).rightChild = nodeList
.get(lastParentIndex * 2 + 2);
}
}
/**
* 先序遍历
*
* 这三种不同的遍历结构都是一样的,只是先后顺序不一样而已
*
* @param node
* 遍历的节点
*/
public static void preOrderTraverse(Node node) {
if (node == null)
return;
System.out.print(node.data + " ");
preOrderTraverse(node.leftChild);
preOrderTraverse(node.rightChild);
}
/**
* 中序遍历
*
* 这三种不同的遍历结构都是一样的,只是先后顺序不一样而已
*
* @param node
* 遍历的节点
*/
public static void inOrderTraverse(Node node) {
if (node == null)
return;
inOrderTraverse(node.leftChild);
System.out.print(node.data + " ");
inOrderTraverse(node.rightChild);
}
/**
* 后序遍历
*
* 这三种不同的遍历结构都是一样的,只是先后顺序不一样而已
*
* @param node
* 遍历的节点
*/
public static void postOrderTraverse(Node node) {
if (node == null)
return;
postOrderTraverse(node.leftChild);
postOrderTraverse(node.rightChild);
System.out.print(node.data + " ");
}
public static void main(String[] args) {
BinTreeTraverse2 binTree = new BinTreeTraverse2();
binTree.createBinTree();
// nodeList中第0个索引处的值即为根节点
Node root = nodeList.get(0);
System.out.println("先序遍历:");
preOrderTraverse(root);
System.out.println();
System.out.println("中序遍历:");
inOrderTraverse(root);
System.out.println();
System.out.println("后序遍历:");
postOrderTraverse(root);
}
}
分享名称:java代码生成树形菜单,java实现树菜单
标题URL:http://ybzwz.com/article/hdijsc.html