在JAVA中如何为菜单添加分隔线?如何创建复选菜单项?如何创建多级菜单?菜单Menu类的对象调用addSeparator();添加分割线,此行代码添加在你要分割线出现的位置上 。
而创建复选菜单 , 用CheckboxMenuItem类创建菜单项就行 。
至于多级菜单,只要把一个Menu类的对象添加到另一个Menu类的对象,就可以产生多级菜单了 。
java中怎样做多级菜单1 。sevice层:
/**
* 构建 点取筛取 树形动态菜单
* @return tree
* @throws BasicException
*/
public String buildTree()throws BasicException{
try {
StringBuffer xmlBuffer = new StringBuffer();
int a = 0;
xmlBuffer.append("d.add(0,-1,'input type=\"checkbox\" name=\"ckb\" id=\"0\" onClick=\"check(this.form.ckb)\" value=https://www.04ip.com/"-1\"/全部');");
xmlBuffer.append("\n");
List list = getDao().findFundInvestType();
if(list!=nulllist.size()!=0){
int b = 0;
for(int i=0;ilist.size();i++){
FundInvestType bean = (FundInvestType)list.get(i);
String code = bean.getInvestCode();
// if is sencond
if(code.length()==2){
b++;
a=i;
xmlBuffer.append("d.add("+b+",0,'input type=\"checkbox\" name=\"ckb\" id=\"0"+b+"\" onClick=\"selectAll(this.form.ckb,this.id)\" value=https://www.04ip.com/""+bean.getInvestCode()+"\" /b"+bean.getInvestName()+"/b','');");
xmlBuffer.append("\n");
}else if(code.length()==10){
//if is second
if(code.substring(2,10).equals("00000000")){
b++;
a=i;
xmlBuffer.append("d.add("+b+",0,'input type=\"checkbox\" name=\"ckb\" id=\"0"+b+"\" onClick=\"selectAll(this.form.ckb,this.id)\" value=https://www.04ip.com/""+bean.getInvestCode()+"\"/b"+bean.getInvestName()+"/b','');");
xmlBuffer.append("\n");
}else{//if is third,it father is second
b++;
int k = a+1;
xmlBuffer.append("d.add("+b+","+k+",'input type=\"checkbox\" name=\"ckb\" id=\"ckb0"+k+"\" value=https://www.04ip.com/""+bean.getInvestCode()+"\"/"+bean.getInvestName()+"','');");
xmlBuffer.append("\n");
}
}
}
}
return xmlBuffer.toString();
} catch (RuntimeException e) {
throw new BasicException(e.getMessage());
}
}
2 。jsp页面:
%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %
%
String webapp=request.getContextPath()+"/fund";
%
html
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title基金投资类型/title
link rel="stylesheet" type="text/css" href="https://www.04ip.com/post/%=webapp%/Pub/Style.css"
link rel="StyleSheet" href="https://www.04ip.com/post/%=webapp%/menu/dtree.css" type="text/css" /
SCRIPT LANGUAGE="JavaScript"
!-- Begin
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 1; ifield.length; i++) {
field[i].checked = true;
field[i].disabled = true;
}
checkflag = "true";
}else {
for (i = 1; ifield.length; i++) {
field[i].checked = false;
field[i].disabled=false;
}
checkflag = "false";
}
}
//------选中二级全选--------
var selectflag = "false";
function selectAll(field,j) {
if (selectflag == "false") {
for (i = 0; ifield.length; i++) {
var b ="ckb"+j;
if(field[i].id==b){
field[i].checked = true;
field[i].disabled=true;
selectflag = "true";
}
}
}else {
for (i = 0; ifield.length; i++) {
var b ="ckb"+j;
if(field[i].id==b||field[i].id==j){
field[i].checked = false;
field[i].disabled = false;
selectflag = "false";
}
}
}
}
//--------取消二级全选-------
function disabledAll(){
field = document.getElementById("myform");
推荐阅读
- 为什么手机积分看不到,手机积分为什么兑换不了
- 怎么把公众号改成个人号,怎么把公众号改成个人号码
- 咕咕空间是虚拟空间吗,咕咕空间安全吗?
- 成人恋爱养成的游戏叫什么,成年恋爱
- vb.net共享盘访问 visual box共享文件夹
- win10删除mysql服务,win10删除mysql服务器
- 2017最新大行网络游戏,2020网络大型游戏
- linux命令行请求网页 linux命令行访问网址
- 什么软件可以修复u盘发热,u盘发烫烧了数据恢复